1、实验四 循环控制实验内容:1、#include void main()double e=1.0,x=1.0,y,detax;int i=1;printf(“n请输入误差:“);scanf(“%lf“,y=1/x;while (y=detax)x*=i;y=1/x;e=e+y;i+=1;printf(“e=%12.10fn“,e);2、#include void main()int n,k,a;printf(“请输入一个数:“);scanf(“%d“,k=2;printf(“该数的分解的质因数有:n“);while(k!=n)a=n%k;if (a=0)printf(“%dn“,k);n=n/k
2、;else k=k+1;printf(“%dn“,k);3、#includevoid main()int a,b,i,r;printf(“请输入长度:“);scanf (“%d“,printf(“请输入宽度:“);scanf (“%d“,for(i=1;ivoid main()int i,j,r;for(i=1;ivoid main()float a,i,sum,average;printf(“请输入一个班的成绩,如果全部统计完成请输入-2n“);while (a!=-2)for (sum=0,i=0;a!=-1;i=i+1)printf(“请输入一个学生的成绩,该班输入完成请输入-1:“);
3、scanf(“%f“,if (a!=-1) sum=sum+a;else break;average=sum/i;printf(“该班的平均成绩为:%4.2fn“,average);printf(“请输入下一个班的成绩,如果全部统计完成请输入-2,继续输入 0:“);scanf(“%f“,printf(“n“);6、#include#includevoid main()int i,random,guess;i=1;random=rand()%100+1;printf(“请输入您猜的数:“);scanf(“%d“,while (guess100|guessrandom)printf(“您猜的数高
4、了n“);else if (guess100|guess10)break;if (iint leap(int year)int leap;if(year%4=0elseleap=0;return leap;void month(int n,int m,int day)int a,x,y,sum,i,j,k,r,z;static int c;char s5=“ “;y=2001;sum=0;printf (“ 日 一 二 三 四 五 六n“);if (ny)for (i=n-y;i!=0;i-)a=leap(n);if (a=1)x=366;elsex=365;sum=sum+x;if (m1)c=sum;c=c+day;z=c/7;r=c%7;elsez=sum/7;r=sum%7;k=0;if (r!=6)while (kvoid main()double a,b,c,x;printf(“请输入 a的值:“);scanf(“%lf“,x=a;c=1;while (c1e-6)b=0.5*(x+a/x);c=b-x;x=b;if (c0) c=-c;printf(“%fn“,x);