网课作业沈科2105

1. 输出以下图形

 

(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=4;i>=1;i--){
  for(j=1;j<=5-i;j++){
   printf(" ");
  }
  for(k=1;k<=2*i-1;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只\n",x,y);
    }
}

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

#include<stdio.h>
main()
{
    int i,j;
    printf("__________九九乘法表_________\n");
    for(i=1;i<=9;i++)
    {
        for(j=1;j<=i;j++)
            printf("%2d*%d=%2d",j,i,i*j);
        printf("\n");
    }

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


    printf("__________________");
}

4.输入一个数判断是不是质数(质数是只能被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:38  舟慕沉  阅读(40)  评论(0)    收藏  举报