资源描述:
《华科周纯杰版c语言问题详解.doc》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、第三章程序和流程控制1.输入两个整数,输出较大者。#includevoidmain(){inta,b;intmax=0;printf("Pleaseinputtwonumbers:");scanf("%d%d",&a,&b);if(a<=b)max=b;elsemax=a;printf("Thelargernumberis%d",max);}2.有3个整数a,b,c,由键盘输入,输出其中最大的数。#includevoidmain(){inta,b,c,max;printf("Pleaseinputt
2、hreenumbers:");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("Thelargestnumberis%d",temp);}3.从1累加到100,用while语句。#include#defineN100voidmain(){inti=1,sum=0;while(i<=N){sum+=i;i++;}printf("sum:%d",sum);}4.已知a1=10,a2
3、=-3,an=3an-1+an-2,求{a}的前十项。#include#defineN10voidmain(){inta[20]={10,-3};inti=0,m=0;for(i=2;ivoidmain(){inta,te
4、mp;printf("Pleaseinputanumbers:");scanf("%d",&a);temp=a%2;if(temp==0)printf("Thenumber%disaneven!",a);elseprintf("Thenumber%disanoddnumber!",a);}6.已知a1=8,an=an-1+bn,b1=1,bn=bn-1+3,求{a}前10项之和。#include#defineN10voidmain(){inta[N]={8},b[N]={1},i,sum=0;for(i=1;
5、ivoidmain(){floatx,y;printf("Pleaseinputafloatnumberx=:");scanf("%f",&x);printf("x=%f",x);if(x<1)y=x;elseif(x>=10)y=3*
6、x-11;elsey=2*x-1;printf("Thevalueofyis:%.3f",y);}8.给一个不多于5位的的正整数,要求:求出它是几位数,分别打印出每一位数字,最后按照逆序打印各位数字,例如原数为321,应输出为123。#include#defineN99999#defineM5voidmain(){inti,j,k,m,b[M];longinta,temp;printf("Pleaseinputanumber:");scanf("%ld",&a);if(a<0
7、
8、a>N)printf("Error
9、ininputdata!!!");else{temp=a;for(i=0;temp!=0;i++){temp=temp/10;}m=i;printf("Thenumbera=%ldhave%dsinglenumbers",a,m);temp=a;for(j=0;j10、tteris:");for(j=m-1;j>=0;j--)printf("%dt",b[j]);printf("");printf("Theinvertednumbersare:")