当前位置:首页 > 电大C语言程序设计形成性考核册答案(1-4)
printf(\
}
输出结果为:
11 14 switch end.
Press any key to continue
2. #include
void main()
{
int i,s=0;
for(i=1;i<=6;i++)
s+=i*i;
printf(\
}
输出结果为:
s=91.
Press any key to continue
3. #include
void main()
{
int i,s1=0,s2=0;
for(i=0;i<10;i++)
.
精品
if(i%2)s1+=i;
else s2+=i;
printf(\
}
输出结果为:
25 20.
Press any key to continue
4. #include
void main()
{
int n=10,y=1;
while(n--){y++;y++;}
printf(\
}
输出结果为:
y=21.
Press any key to continue
5. #include
void main()
{
int f,f1,f2,i;
f1=f2=1;
.
精品
.
printf(\
for(i=3;i<=10;i++){
f=f1+f2;
printf(\
if(i%5==0)printf(\
f1=f2;
f2=f;
}
printf(\
}
输出结果为:
1 1 2 3 5
8 13 21 34 55
Press any key to continue
6. #include
#include
void main()
{
int i,n;
for(n=2;n<=20;n++){
int temp=(int)sqrt(n);//sqrt(n)求出n的平方根并取整
for(i=2;i<=temp;i++)
精品
if(n%i==0)break;
if(i>temp)printf(\
}
printf(\
}
输出结果为:
2 3 5 7 11 13 17 19
Press any key to continue
7. #include
#include
const int M=20;
void main()
{
int i,c2,c3,c5;
c2=c3=c5=0;
for(i=1;i<=M;i++){
if(i%2==0)c2++;
if(i%3==0)c3++;
if(i%5==0)c5++;
}
printf(\
}
.
精品
共分享92篇相关文档