1、1.要求在屏幕上输出下一行信息。This is a c program.程序:#includeint main()printf(“this is a c program.n”);return 0;2.求两个整数之和。程序:#includeint main()int a,b,sum;a=122;b=234;sum=a+b;printf(“sum is %dn”,sum);return 0;3.求两个整数之间的较大者。程序:#includeint main()int max(int x,int y);int a,b,c;scanf(“%d,%d“,c=max(a,b);printf(“max=%d
2、n“,c);return 0;int max(int x,int y)int z;if(xy)z=x;else z=y;return(z);4.有人用温度计测量出华氏发表示的温度(如 69F) ,今要求把她转换成以摄氏法表示的温度(如 20) 。公式:c=5(f-32)/9.其中 f代表华氏温度,c 代表摄氏温度。程序:#includeint main()float f,c;f=64.0;c=(5.0/9)*(f-32);printf(“f=%fnc=%fn“,f,c);return 0;5.计算存款利息。有 1000元,想存一年。有一下三种方法可选:(1)活期:年利率为 r1;(2)一年定期
3、:年利率为r2;(3)存两次半年定期:年利率为 r3。分别计算一年后按三种方法所得到的本息和。程序:#includeint main()float p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;p1=p0*(1+r1);p2=p0*(1+r2);p3=p0*(1+r3/2)*(1+r3/2);printf(“p1=%fnp2=%fnp3=%fn“,p1,p2,p3);return 0;6.给定一个大写字母,要求以小写字母输出。程序:#includeint main()char c1,c2;c1=A;c2=c1+32;printf(“%cn”,c2
4、);printf(“%dn”,c2);return 0;7.给出三角形的三边长,求三角形的面积。公式:若给定三角形的三边长,且任意两边之长大于第三边。则:area= ()()()其中 s=(a+b+C)/2.程序:#include#includeint main()double a,b,c,area;a=3.67;b=5.43;c=6.21;s=(a+b+c)/2;area=sqrt(s*(s-a)*(s-b)*(s-c);printf(“a=%ftb=%ftc=%fn”,a,b,c);printf(“area=%fn”,area);return 0;8.求 ax2+bx+c=0方程的根。a,
5、b,c 由键盘输入,设 b2-4ac0.程序:#include#includeint main()double a,b,c,disc,x1,x2,p,q;scanf(“%lf%lf%lf”,disc=b*b-4*a*c;if(discint main()char a=B,b=O,c=Y;putchar(a);putchar(b);putchar(c);putchar(n);return 0;10. 用三个 getchar函数先后向计算机输入 BOY三个字符,然后用 putchar函数输出。程序:#includeint main()char a,b,c;a=getchar();b=getchar
6、();c=getchar();putchar(a);putchar(b);putchar(c);putchar(n);return 0;或#includeint main()putchar(getchar();putchar(getchar();putchar(getchar();putchar(n);return 0;11. 用 getchar函数从键盘读入一个大写字母,把它转换成小写字母,然后用 getchar函数输出对应的小写字母。程序:#includeint main()char c1,c2;c1=getchar();c2=c1+32;putchar(c2);putchar(n);re
7、turn 0;12. 输入两个实数,按代数值由小到大的顺序输出这两个数。(参照将两个杯子中的水互换,必须借助第三个杯子) 。程序:#includeint main()float a,b,t;scanf(“%f,%f”,if(ab)t=a;a=b;b=t;printf(“%5.2f,%5.2fn”,a,b);return 0;13. 输入 a,b,c 三个数,要求由小到大的顺序输出。程序:#includeint main()float a,b,c,t;scanf(“%f,%f,%f“,if(ab);t=a;a=b;b=t;if(ac)t=a;a=c;c=t;if(bc)t=b;b=c;c=t;p
8、rintf(“%5.2f,%5.2f,%5.2fn“,a,b,c);return 0;14输入一个字符,判断它是否为大写字母,如果是,将它转换成小写字母,如果不是,不转换。然后输出最后得到的字符。程序:#includeint main()char ch;scanf(“%c”,ch=(ch=Ascanf(“%c“,if(ch=Ascanf(“%d“,if(xint main()char grade;scanf(“%c“,grade);printf(“You score:n“);switch(grade)caseA:printf(“85100n“);break;caseB:printf(“7084
9、n“);break;caseC:printf(“6069n“);break;caseD:printf(“int main()int leap,year;printf(“please enter year:“);scanf(“%d“,if(year%4=0)if(year%100=0)if(year%400=0)leap=1;elseleap=0;else leap=1;else leap=0;if(leap)printf(“%d is a leap yearn“,year);elseprintf(“%d is not a leap yearn“,year);return 0;或#include
10、int main()int leap,year;printf(“please enter year:“);scanf(“%d“,if(year%4!=0)leap=0;else if(year%100!=0)leap=1;else if(year%400!=0)leap=0;elseleap=1;if(leap=1)printf(“%d is a leap yearn“,year);elseprintf(“%d is not a leap yearn“,year);return 0;或#includeint main()int leap,year;printf(“please enter ye
11、ar:“);scanf(“%d“,if(year%4=0elseleap=0;if(leap=1)printf(“%d is a leap yearn“,year);elseprintf(“%d is not a leap yearn“,year);return 0;18. 求 ax2+bx+c=0方程的根。a,b,c 由键盘输入。 (完整版)程序:#include#includeint main()double a,b,c,disc,x1,x2,x3,realpart,imagepart;scanf(“%lf,%lf,%lf“,printf(“The equation“);if(fabs(a
12、)1e-6)printf(“has two distinct real rootsn%8.4f,%8.4f“,x1,x2);x1=(-b+sqrt(disc)/2*a;x2=(-b-sqrt(disc)/2*a;elserealpart=-b/2*a;imagepart=sqrt(-disc)/2*a;printf(“has two complex roots:n“);printf(“%8.4f+%8.4fin“,realpart,imagepart);printf(“%8.4f-%8.4fin“,realpart,imagepart);return 0;/注释:由于 b*b-4*a*c(di
13、sc)是实数,而实数在计算和存储时会有一些微小的误差,因此不能直接进行如下判断:/“if(disc=0)“,因为这样可能出现本来是零的量,由于上述误差而判别为不等于零而导致结果错误,/所以采取的办法是判别 disc的绝对值(fabs(disc) )是否小于一个很小的数(例如:1e-6) 。如果小于此数,则认为 disc=0.19.给出一个不多出 5位的正整数,要求:(1):求出它是几位数;(2):分别输出每一位数字;(3):按逆序输出各位数字,例如原数为 321,输出 123。程序:#includeint main()int num,indiv,ten,hundred,thousand,ten
14、_thousand,place;printf(“请输入一个正整数(099999):“);scanf(“%d“,if(num9999)place=5;else if(num999)place=4;else if(num99)place=3;else if(num9)place=2;elseplace=1;printf(“位数为:%dn“,place);ten_thousand=num/10000;thousand=(num-ten_thousand*10000)/1000;hundred=(num-ten_thousand*10000-thousand*1000)/100;ten=(num-te
15、n_thousand*10000-thousand*1000-hundred*100)/10;indiv=(num-ten_thousand*10000-thousand*1000-hundred*100-ten*10);printf(“每一个数字分别为:“);printf(“%d,%d,%d,%d,%dn“,ten_thousand,thousand,hundred,ten,indiv);switch(place)case 5:printf(“反序数字为:%d%d%d%d%dn“,indiv,ten,hundred,thousand,ten_thousand);break;case 4:pr
16、intf(“反序数字为:%d%d%d%dn“,indiv,ten,hundred,thousand);break;case 3:printf(“反序数字为:%d%d%dn“,indiv,ten,hundred);break;case 2:printf(“反序数字为:%d%dn“,indiv,ten);break;case 1:printf(“反序数字为:%dn“,indiv);break;return 0;20.求 1+2+3+4+5+100。程序:#includeint main()int i=1,sum=0;while(iint main()int i=1,sum=0;dosum=sum+i;i+;while(iint main()int i=1;doprintf(“%dn“,i+);while(i=100);return 0;22.