第六次作业

1.编写程序,输出以下图形

*                          *******

**                          *****

***                          ***

****                          *

*****

#include<stdio.h>

main(){

         int i,j;

         for(i=1;i<=5;i++)

         {

                  for(j=1;j<=i;j++){

                          printf("*");

                  }

                  printf("\n");

         }

}

 

 

#include<stdio.h>

main(){

         int i,j,k;

         for(i=1;i<=4;i++){

                  for(j=1;j<=i;j++)

                          printf(" " );

         for(k=1;k<=9-2*i;k++)

                  printf("*");

         printf("\n");

         }

}

 

 

 

 

2.编写程序,通过for语句解决“鸡兔同笼”问题。

#include<stdio.h>

main(){

         int x,y;

         for(x=0;x<=35;x++)

         {

                  y=35-x;

                  if(2*x+4*y==94)

                          printf("鸡:%d只  兔子:%d只",x,y);

         }

}

 

 

3.编写程序,打印“九九乘法表”。

#include<stdio.h>

main(){

         int x,y;

         for(x=1;x<=9;x++)

         {

                  for(y=1;y<=x;y++)

                  printf("%2d*%2d=%2d",y,x,x*y);

         printf("\n");

         }

}

 

 

main() {

         int i,m;

         printf("请输入一个整数:\n");

         scanf("%d",&m) ;

         for(i=2;i<m;i++)

                  if(m%i==0) break;

                  if(i<m)

                          printf("%d不是质数\n",m);

                  else printf("%d是质数\n",m);

}

 

posted @ 2021-11-09 10:45  问世间什么最美丽  阅读(33)  评论(0)    收藏  举报