资源描述:
《华科周纯杰版c语言答案》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、第三章程序和流程控制I.输入两个整数,输出较大者。#includevoidmain(){inta.b;intmax=0;printf(MPleaseinputtwonumbers:11);scanf(”%d%d",&a,&b);if(a<=b)max=b;elsemax=a;printf(MThelargernumberis%dn,max);}2.冇3个整数a,b,c,由键盘输入,输出英中最大的数。#includevoidmain(){inta,b,c,max;printf(HPlease
2、inputthreenumbers:0);scanf(”%d%d%d“,&a,&b,&c);if(a>b){if(a>c)max=a;elsemax=c;}else{if(b>c)max=b;elsemax=c;}printf(MThelargestnumberis%d,temp);}3.从1累加到100,用while语句。#includc#defineN100voidmain()inti=hsum=O;while(i<=N){sum+=i;i++;}printf("sum:%d'sum);}2.已
3、知al=10,a2=_3,an=3an-l+an-2,求{a}的前十项。#include#dcfincN10voidmain(){inta[20]={10,-3);inti=0,m=();for(i=2;ivo
4、idmain(){inta,temp;printf(HPleaseinputanumbers:H);scanf(”%d”,&a);temp=a%2;if(tcmp==0)printf(HThenumber%disaneven!H5a);elseprintf(nThenumber%disanoddnumber!,a);}4.已知al=8,an=an・l+bn,bl=1,bn=bn・l+3,求{a}前10项之和。#include#dcfincN10voidmain(){inta[N]={8},b[N]
5、={1},i,sum二0;for(i=l;ivoidmain(){floatx,y;printf("Pleaseinputafloatnumberx=:M);scanf("%f&x);printf(”x=%f',x);if(
6、x<1)y二x;elseif(x>=10)y=3*x-l1;elsey=2*x-l;printf("Thevalueofyis:%.3f”,y);}3.给一个不多于5位的的正整数,要求:求出它是儿位数,分别打印出每一位数字,最后按照逆序打印各位数字,例如原数为321,应输岀为123。#include#dcfincN99999#defineM5voidmain()inti,j,k,m,b[M];longinta,temp;printf(MPleaseinputanumber:H);scanf("%ld",
7、&a);if(a<()
8、
9、a>N)printf("Errorininputdata!!!");else{temp=a;fbr(i=0;temp!=0;i++){temp=temp/10;}m=i;printf(MThenumbera=%ldhave%dsinglenumbersiV;a,m);temp=a;for(j=0;j10、[k]);}printf(““);printf(neveryletteris:”);for(j=m-l;j>=();j—)printf(”%dt”,b[j]);printfC*^");printf("Theinvertednumbersare:");f