资源描述:
《第二次C语言作业》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、C语言实验报告第二题:#includeintmain(void){intmj,sum;scanf("%d",&m);i=m,sum=O;while(i<=100){sum=sum+i;i卄;}p「intf(“%d”,sum);*C:Docu>ents10return0;andSettingsfounderDebug11291140.exe*:5005Pressanykeytocontinue第五题:#includeintmain(void){intnJ,flag,g;doubleterm,sum;flag=1;i=1;term=1.0
2、;sum=0;g=1;scanf(”%d“,&n);while(g<二n){term=flag*1.0/i;sum=sum+term;flag=-flag;i二i+3;g++;}printf(,'sum=%.31f,,,sum);return0;c、*C:Docu>entsandSettingsfounderDebug45456.exe*3sun=0.893Pressanykeytocontinue匚*C:Docu>entsandSettingsfounderDebug45456・exe"10sum=0.819Pressanykeytocontinue第六题
3、:#includeintmain(void){intfahr,lower,upper;doubleCelsius;printf(/ZEnterlower/');scanf(〃%d〃,&1ower);printf(〃Enterupper:z,);seanf(〃%d〃,&upper);printf(z,fahrcclsius'rT);for(fahr=lower;fahr<=upper;fahr=fahr+2){celsius二(5.0/9.0)*(fahr-32);printf(〃%d%6・If〃,fahr,celsius);}c'*C:Docu*ents
4、andSettingsfounderDebugCpp2.exEnterlower:32Ent"upper:35fahrcelsius320.0341.1Pressanykeytocontinuec*C:YDocimentsandSettingsfounderDebugCpp2.exeEnterlower:40Enterupper:30fahrCelsiusPressanykeytocontinue第七题:#includeintmain(void){intm,n,a,b;doubleiteml,item2,sum;scanf(”%d,%d”,&m,&
5、n);item1=1;item2=1;sum=0;for(a=l;a<=m;a++){iteml=iteml*a;}for(b=1;b<=n;b++){item2=item2*b;1sum=iteml+item2;printf(”%.01f”,sum);C:Docu>entsrelum0;andSettingsfounderDebugCpp4.exe*3,840326Pressanykeytocontinue第三题:#ineludeintmain(void){intletter,blank,digit,other,i;charch;Ietter=b
6、lank=digit=other=0;printf(nEnter10characters:n);for(i=l;i<=10;i++){ch=getchar();if((ch>='a!&&chv=N)
7、
8、(ch>='A'&&ch<='Z'))letter++;elseif(ch>='0'&&chv二9)digit++;elseif((ch='')
9、
10、(ch=''))blank++;elseolher++;}printf(',letter=%d,blank=%d,digit=%d,other=%dH,letter,blank,digit,other);return0;c、*
11、C:DebugCpp1.exe*Enter10characters:Reloe123?letter=5J.blank=2J.digit=3/.other=0Pressanykeytocontinue第四题:#include〈stdio.h>intmain(void){chargrade;printf(z,输入等级:〃);scanf("%c",&grade);switch(grade){case'A':printf(,,90-100,/);break;case'B':printf("8