《简单的C语言编程题例题》由会员分享,可在线阅读,更多相关《简单的C语言编程题例题(5页珍藏版)》请在金锄头文库上搜索。
1、1、编写程序,把 560 分钟换算成用小时和分钟表示,然后输出。解:其所编程序如下#include “stdio.h“void main() int a=560,b=60,c,d;c=a/b;d=a%b;printf(“560分钟=%d小时%d分钟“,c,d); 2、编写程序,输入两个整数:1500 和 350,求出它们的商和余数并 进行输出。解:所编程序如下#include “stdio.h“void main() int a,b,c,d;printf(“Input two numbers:“);scanf(“%d%d“,c=a/b;d=a%b;printf(“c=%d,d=%dn“,c,d
2、); 3、编写程序,读入三个双精度数,求出它们的平均值并保留此平均 值小数点后一位数,对小数点后的第二位数进行四舍五入,最后输出结果。解:所编程序如下#include “stdio.h“void main() double a,b,c,ave;printf(“Enter three numbers:“);scanf(“%lf%lf%lf“,ave=(a+b+c)/3;printf(“(1)ave=%fn“,ave);ave=(int)(ave*10+0.5)/10.0;printf(“(2)ave=%fn“,ave); 4、编写程序,读入三个整数给 a、b、c,然后交换它们中的数,把a 中原来
3、的值给 b,把 b 中原来的值给 c,把 c 中原来的值给 a,然后输出 a、b、c。解:所编程序如下#include “stdio.h“void main() int a,b,c,m,n,t;printf(“Enter three numbers:“);scanf(“%d%d%d“,printf(“a=%d,b=%d,c=%dn“,a,b,c);m=a;n=b;t=c;b=m;c=n;a=t;printf(“a=%d,b=%d,c=%d“,a,b,c); 5、编写程序,输入一位学生的生日(年:y0、月:m0、日:d0) ,并输入当前的日期(年:y1、月:m1、日:d1) ,输出该生的实际年龄
4、。解:所编程序如下#include “stdio.h“void main() int y0,m0,d0,y1,m1,d1,age;printf(“请输入该学生的生日:“);scanf(“%d%d%d“,printf(“该学生的生日是%d年%d月%d日n“,y0,m0,d0);printf(“请输入当前日期:“);scanf(“%d%d%d“,printf(“当前日期是%d年%d月%d日n“,y1,m1,d1);age=y1-y0;if(m1b) t=a;a=b;b=t;if(ac) t=a;a=c;c=t;if(bc) t=b;b=c;c=t;printf(“MAX=%dn“,c);8、对于以下函数: )100( 1)0( 1)05(xxxxxx y编写程序,要求输入 x 的值,输出 y 的值。解:所编程序如下#include “stdio.h“void main() int x,y;printf(“Enter a number:“);scanf(“%d“,if(-5x printf(“y=%dn“,y);if(x=0) y=x-1; printf(“y=%dn“,y);if(0x printf(“y=%dn“,y);