1、C语言实训题16章1.3.1:请参照本章例题,编写一个 C 程序,从键盘上输入圆的半径,求园的周长 和以此半径所组成的球的体积。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() float r,c,v,pi=3.14;printf(r:); scanf(%f,&r);c=2*pi*r;v=4.0/3*pi*r*r*r;printf(c=%fn,c);printf(v=%fn,v);getch();132:编写一个C程序,输入45, 21, 60三个数字,输出其中的最大者。/* HELLO.C - Hello,
2、world */#include stdio.h#include conio.hint max(int x,int y,int z)int m;m=xy?x:y;return(mz?m:z);main() int x,y,z;printf(x:); scanf(%d,&x);printf(y:);scanf(%d,&y);printf(z:);scanf(%d,&z);printf(max=%dn,max(x,y,z);getch();2.6.1.1: 观察分析程序的结果,并与人工计算结果进行比较。/* HELLO.C - Hello, world */#include stdio.hvoid
3、 main()char c1,c2;c1=97;c2=98;printf(%c %cn,c1,c2);printf(%d %dn,c1,c2);c1=c1-(a-A);printf(%c %cn,c1,c2);getch();2.6.2: 参照下列求圆面积与园周长的程序,编写已知圆半径、圆柱高,求圆周 长和圆柱体积的程序。/* HELLO.C - Hello, world */#include stdio.h#define pi 3.1415926void main() float r,h,v,len;printf( r:); scanf(%f,&r);printf( h:);scanf(%f
4、,&h);len=2*pi*r;v=pi*r*r*h;printf(n v=%f,length=%f,v,len);getch();3.7.1: 编写程序,使得该程序运行后显示下面一首诗:life is dear indeed,love is priceless too, but for freedom s sake, I may part with the two./* HELLO.C - Hello, world */#include stdio.h#include conio.hmain()printf(life is dear indeed,nlove is priceless too
5、,nbut for freedoms sake,nI may part with the two.);getch();3.7.2: 用格式控制符打印下面图形:*/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain()getch();3.7.3:编写程序,输入一个华氏温度(F),按下面的公式计算并输出对应的摄 氏温度(C)计算公式为C=5(F-32)/9 。/* HELLO.C - Hello, world */#include stdio.h#include conio.h main() float F,C; prin
6、tf(F:); scanf(%f,&F);C=5*(F-32)/9;printf(C=%fn,C); getch();4.5.1: 编写程序,输入一个日期,判断该日期是这一年的第几天/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() int day,month,year,sum,leap;printf(nplease input year,month,dayn);scanf(%d,%d,%d,&year,&month,&day);switch(month)case 1:sum=0;break;case 2:sum
7、=31;break;case 3:sum=59;break;case 4:sum=90;break;case 5:sum=120;break;case 6:sum=151;break;case 7:sum=181;break;case 8:sum=212;break;case 9:sum=243;break;case 10:sum=273;break;case 11:sum=304;break;case 12:sum=334;break;default:printf(data error);break;sum=sum+day;if(year%400=0|(year%4=0&year%100!=
8、0)leap=1;elseleap=0;if(leap=1&month2)sum+;printf(it is the %dth dayn,sum);getch();4.5.2: 编写程序,对于输入的三个数,将他们降序输出/* HELLO.C - Hello, world */#include stdio.h#include conio.h main() float x,y,z,temp;printf(Please input three number:n);scanf(%f,%f,%f,&x,&y,&z);if (xy)temp=x;x=y;y=temp;if (xz)temp=x;x=z;z
9、=temp;if (yz)temp=y;y=z;z=temp;printf(the sequence is:%3.1f,%3.1f,%3.1fn,z,y,x);getch();4.5.4: 某大型电器公司在国庆节期间推出以下促销优惠活动:当天所购商品价 值在 20000 元以上(包括 20000 元)的顾客,将享受 7.5 折优惠;当天所购商 品价值在 15000 元以上(包括 15000 元)的顾客,将享受 8 折优惠;当天所购 商品价值在 10000元以上(包括 10000 元)的顾客,将享受 8.5 折优惠;当天 所购商品价值在 5000 元以上(包括 5000 元)的顾客,将享受 9
10、折优惠;其他 顾客享受 9.5 折优惠。编写实现该优惠活动的程序。/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain()float x;float y;printf(please input a x:n);scanf(%f,&x);if(x=20000)y=x*0.75;else if (x=15000)y=x*0.8;else if (x=10000)y=x*0.85;else if (x=5000) y=x*0.9; else y=x*0.95; printf(%fn,y); getch();4.5.5:写出实现
11、以下函数的对应程序,要求:输入x,计算并输出函数y的值(保 留两位小数)。X+10 ,( x0)/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain()float x;float y;printf(please input a x:n);scanf(%f,&x);if(x0) y=x*30;else if(x=1000&x10000)a=x%10;printf(%dn,a); b=(x/10)%10;printf(%dn,b); c=(x/100)%10;printf(%dn,c);d=(x/1000)%10;prin
12、tf(%dn,d); y=b*1000+a*100+d*10+c;printf(%dn,y);elseprintf(sorry ERROR);getch();5.5.3.2: 编一程序输出如下图形:112112321123432112345432112345654321/* HELLO.C - Hello, world */#include stdio.h#include conio.hmain() int i,j;for(i=1;i=6;i+) for(j=1;j=6-i;j+)printf( );for(j=1;j=1;j-)printf(%d,j);printf(n);getch();从
13、第。5.6.3: 设计程序输出 Fibonacci 数列的前 50 个数,其开始两个数是 1、1 三个数开始,每个数等于前两个数之和。例如, 1、1、2、3、5、8、 13、 /* HELLO.C - Hello, world */#include stdio.h#include conio.h int main()long x16 = 0,1;int i;for(i=2;i16;i+) xi = xi-1+xi-2; for(i=1;i16;i+) printf(F%d=%dn,i,xi);getch ();5.6.7: 用循环程序输出以下图案。*/* HELLO.C - Hello, world */#inc
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1