第一范文网 - 专业文章范例文档资料分享平台

电大C语言程序设计形成性考核册答案(1-4)

来源:用户分享 时间:2025/5/22 9:09:43 本文由loading 分享 下载这篇文档手机版
说明:文章内容仅供预览,部分内容可能不全,需要完整文档或者需要复制内容,请下载word后使用。下载word有问题请添加微信号:xxxxxxx或QQ:xxxxxx 处理(尽可能给您提供完整文档),感谢您的支持与谅解。

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(\

}

输出结果为:

10 6 4

Press any key to continue

8. #include

#include

const int M=20;

void main()

{

int i,s;

for(i=1,s=0;i<15;i++){

if(i%2==0 || i%3==0)continue;

printf(\

s+=i;

电大C语言程序设计形成性考核册答案(1-4).doc 将本文的Word文档下载到电脑,方便复制、编辑、收藏和打印
本文链接:https://www.diyifanwen.net/c1muo48wiz64bptb11x4w7g2499iozz00mmq_2.html(转载请注明文章来源)
热门推荐
Copyright © 2012-2023 第一范文网 版权所有 免责声明 | 联系我们
声明 :本网站尊重并保护知识产权,根据《信息网络传播权保护条例》,如果我们转载的作品侵犯了您的权利,请在一个月内通知我们,我们会及时删除。
客服QQ:xxxxxx 邮箱:xxxxxx@qq.com
渝ICP备2023013149号
Top