当前位置:高等教育资讯网  >  中国高校课件下载中心  >  大学文库  >  浏览文档

《C语言程序设计》课程教学资源:实验四参考答案

资源类别:文库,文档格式:DOC,文档页数:2,文件大小:23.5KB,团购合买
点击下载完整版文档(DOC)

1.简单循环编程 (2)输入一行字符,以回车键作为结束标志,分别统计出大写字母、小写字母 空格、数字和其它字符的个数 #indludestdio, h mal chan int capital=0, alpha=0, space=O, number=0, other=0; printf( \nplease input some chars(ending in n): while(ch=getchar=\n) f(dh>=65&&ch=97&&ch=48&&ch<=57) number++ else if(ch==) space++ else other++ printf \capital: %/d, alpha: %d, number: %d, space: %d other: %d"capital, a pha, number space other); 2递推问题编程 (3)有一分数序列: 23581321 求出这个数列的前20项之和 maino int i m=2n=1,t. float sum=0: for(i=1;<=20;++) sum=sum+1.0*m/n m=m+n printf( \nThe sum is %f sum)

1.简单循环编程 (2) 输入一行字符,以回车键作为结束标志,分别统计出大写字母、小写字母、 空格、数字和其它字符的个数。 #include “stdio.h” main() { char ch; int capital=0,alpha=0,space=0,number=0,other=0; printf(“\nPlease input some chars(ending in ‘\n’):”); while(ch=getchar()!=’\n’) { if(ch>=65&&ch=97&&ch=48&&ch<=57) number++; else if(ch==‘ ’) space++; else other++; } printf(“\ncapital:%d,alpha:%d,number:%d,space:%d,other:%d”,capital,a lpha,number,space,other); } 2.递推问题编程 (3) 有一分数序列: , 13 21 , 8 13 , 5 8 , 3 5 , 2 3 , 1 2 求出这个数列的前 20 项之和。 main() { int i,m=2,n=1,t; float sum=0; for(i=1;i<=20;i++) { sum=sum+1.0*m/n; t=m; m=m+n; n=t; } printf(“\nThe sum is %f”,sum); }

(6)求Sn=a+aa+aa+…+a…a的值,其中a是一个数字,如 2+22+222+2222+2222(此时n=5),n由键盘输入 #ⅰ ndude" math. h" mal float s,sum=O int i, n, a: printf( \nplease input the a, n scanf(%d%d &a, &n) S=a for(i=1;i=l; day--) {×1=(X2+1)*2; printf("\nzongshu=%d",x1;

(6) 求    n a Sn a aa aaa aa a 个 = + + + + 的 值 , 其 中 a 是 一 个 数 字 , 如 2+22+222+2222+22222(此时 n=5),n 由键盘输入。 #include “math.h” main() { float s,sum=0; int i,n,a; printf(“\nPlease input the a,n:”); scanf(“%d%d”,&a,&n); s=a; for(i=1;i=1;day--) { x1=(x2+1)*2; x2=x1; } printf("\nzongshu=%d",x1); }

点击下载完整版文档(DOC)VIP每日下载上限内不扣除下载券和下载次数;
按次数下载不扣除下载券;
24小时内重复下载只扣除一次;
顺序:VIP每日次数-->可用次数-->下载券;
已到末页,全文结束
相关文档

关于我们|帮助中心|下载说明|相关软件|意见反馈|联系我们

Copyright © 2008-现在 cucdc.com 高等教育资讯网 版权所有