正在加载图片...
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<=90) capital else if(ch>=97&&ch<=122) alpha++i else if(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<=90) capital++; else if(ch>=97&&ch<=122) alpha++; else if(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); }
向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有