第七次作业

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;

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

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

                     printf("*");

              }

              printf("\n");

       }

}

 

练习册 P64  8

#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只\n",x,y);

       }

 

}

 

 

练习册 P64  9

#include<stdio.h>

main(){

       int i,j;

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

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

                     printf("%d*%d=%d\t",i,j,i*j);

              }

      

              printf("\n");

       }

       }

 

 

输入一个数判断是不是质数(质数是只能被1和自身整除的数)

#include<stdio.h>

main(){

 int a,b,c;

 scanf("%d",&a);

 for(c=2;c<a;c++){

  if(a%c==0)

   break;

 }

 if(c>=a)

  printf("%d质数",a);

 else

  printf("%d合数",a);

}

 

posted @ 2021-11-09 10:29  李治浩  阅读(28)  评论(0编辑  收藏  举报