第七次作业
1. 输出以下图形
*
**
***
****
*****
*******
*****
***
*
#include <stdio.h>
main(){
int i,j;
for (i=1;i<=5;i++)
{
for (j=1;j<=9-2*i;j++)
printf("*");
printf("\n");
}
}

#include <stdio.h>
main(){
int i,j;
for (i=1;i<=4;i++)
{
for (j=1;j<=9-2*i;j++)
printf("*");
printf("\n");
}
}

2 .练习册 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只鸡\n有%d只兔子",x,y);
}
}

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

4.输入一个数判断是不是质数(质数是只能被1和自身整除的数)
#include<stdio.h>
main(){
int i,n;
printf("请输入n:");
scanf("%d",&n);i=2;
while(i<n)
{
if(n%i==0)break;i++;
}
if(i==n)
printf("YES!\n",n);
else
printf("NO!\n",n);
}


浙公网安备 33010602011771号