C语言知识基本编程题.doc
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《C语言知识基本编程题.doc》由会员分享,可在线阅读,更多相关《C语言知识基本编程题.doc(17页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、. 复习题 C程序设计编程题1.输入2个整数,求两数的平方和并输出。 #include void main() intt a ,b,s; printf(please input a,b:n); scanf(%d%d”,&a,&b); s=a*a+b*b; printf(the result is %dn,s); 2. 输入一个圆半径(r),当r0时,计算并输出圆的面积和周长,否则,输出提示信息。#include #define PI 3.14 void main() float r ,s , l; printf(please input r:n); scanf(%f”,&r);if (r=0)
2、 s=pi*r*r; l=2*i*r ; printf(the area is %fn,s);printf(the circumference is %fn,l);else printf(input error!n); 3、函数y=f(x)可表示为: 2x+1 (x0) 编程实现输入一个x值,输出y值。 #include void main() int x,y;scanf(“%d”,&x);if(x0) y=2*x-1;else y=0;printf(“%d”,y);4、编写一个程序,从4个整数中找出最小的数,并显示此数。#include void main( )int a,b,c,d,t;
3、scanf (“%d,%d,%d,%d ”,&a,&b,&c,&d); if (ab) t=a; a=b; b=t; if (ac) t=a; a=c; c=t; if (ad) t=a; a=d; d=t; printf (“min = %d n”,a);5有一函数当x0时,y=3,当x=0时y=5,编程,从键盘输入一个x值,输出y值。#include void main()int x,y;scanf(%d,&x);if (x0) y=1;else if(x=0) y=5;else y=3;printf(x=%d,y=%dn,x,y);6从键盘输入两个数,求出其最大值(要求使用函数完成求最大
4、值,并在主函数中调用该函数) #include float max(float x,float y);void main() float a,b,m;scanf(%f,%f,&a,&b);m=max(a,b);printf(Max is %fn,m);float max(float x,float y)float temp;if (xy) temp=x; x=y; y=temp;return(x);7、从键盘输入你和你朋友的年龄,编成判断谁的年龄最大,并打印最大者的年龄。#include void main()int yourAge, hisAge;printf(Please enter yo
5、ur age:);scanf(%d, &yourAge); /*输入你的年龄yourAge*/printf(Please enter your friends age:);scanf(%d, &hisAge); /*输入你朋友的年龄hisAge*/if (yourAge = hisAge) printf(You are older! Your age is = %dn, yourAge); if (hisAge yourAge)printf(Your friend is older! HisAge age is = %dn, hisAge); 8、键盘输入2个加数,再输入答案,如果正确,显示“
6、right”,否则显示“error”#include “stdio.h”void main( )int a,b,c; printf(“please input a and bn”);scanf (%d,%d”,&a,&b); printf(“please input the answer for a+bn”);scanf (%d”,&c); if (c=a+b) printf(“rightn”); else printf(“errorn”);9. 编一程序每个月根据每个月上网时间计算上网费用,计算方法如下: 要求当输入每月上网小时数,显示该月总的上网费用(6分)#include void ma
7、in() int hour; float fee; printf(“please input hour:n”); scanf(“%d”,&hour); if(hour=10&hour=50) fee=3*hour; else fee=hour*2.5; printf(“The total fee is %f”,fee);10.神州行用户无月租费,话费每分钟0.6元,全球通用户月租费50元,话费每分钟0. 4元。输入一个月的通话时间,分别计算出两种方式的费用,判断哪一种合适。 #include void main() float a,x,y; printf(“n请输入您的话费:”); scanf
8、(“%f,”,&a); x= 0.6*a; y=50+0.4*a; printf (“神州行话费为: %fn”,x);printf (“全球通话费为: %fn”,y); if (x=y) printf(“建议使用全球通”); else printf(“建议使用神州行); 11个人所得税计算,应纳税款的计算公式如下:收入税率收入收入1000元的部分53000元收入2000元的部分106000元收入3000元的部分15收入6000元的部分20输入某人的收入,计算出应纳税额及实际得到的报酬。(7分)(如需连续计算多个人的纳税情况,直到输入负数为止,程序应如何改进?试写出程序)#include “st
9、dio.h”void main() int grade; float income,tax,money; printf(“please input your incomen”);scanf (“%f”,&income); if (income0) printf(“the input is error”); else grade=(int)income/1000; switch(grade) case 0 : tax=0;break; case 1 : tax=(income-1000)*0.05;break; case 2 : tax=50+(income-2000)*0.1;break; c
10、ase 3 :case 4 :case 5 : tax=150+(income-3000)*0.15;break;default: tax=600+(income-6000)*0.2; money=income-tax; printf(“n tax=%f, money=%f”,tax, money); 12.从键盘上输入一个百分制成绩score,按下列原则输出其等级:score90,等级为A;80score90,等级为B;70score80,等级为C;60score70,等级为D;score60,等级为E。 #include void main()int data; char grade; p
11、rintf(Please enter the score:);scanf(%d”, &data); switch(data/10) case 10: case 9 : grade=A; break; case 8: grade=B; break;case 7: grade=C; break; case 6: grade=D; break; default: grade=E; printf(the grade is %c”,grade);*13. 编程设计一个简单的计算器程序。从键盘输入2个操作数,1个运算符,当运算符为加(+)、减(-)、乘(*)、除(/)时,输出计算结果 #include v
12、oid main() int data1, data2; /*定义两个操作符*/char op; /*定义运算符*/printf(Please enter the expression:);scanf(%d%c%d, &data1, &op, &data2); /*输入运算表达式*/switch(op) /*根据输入的运算符确定要执行的运算*/ case +: /*处理加法*/printf(%d + %d = %d n, data1, data2, data1 + data2); break;case -: /*处理减法*/printf(%d - %d = %d n, data1, data2
13、, data1 - data2);break;case *: /*处理乘法*/printf(%d * %d = %d n, data1, data2, data1 * data2); break;case /: /*处理除法*/if (0 = data2) /*为避免出现溢出错误,检验除数是否为0*/printf(Division by zero!n);else printf(%d / %d = %d n, data1, data2, data1 / data2); break;default: printf(Unknown operator! n);14. 从键盘输入10个整数,统计其中正数
14、、负数和零的个数,并在屏幕上输出。#include void main( ) int a10, i,p=0,n=0,z=0; printf(“please input number”); for(i=0;i0) p+;else if (ai0) n+;else z+ printf(“正数:%5d, 负数:%5d,零:%5dn”,p,n,z);15、编程序实现求1-10之间的所有数的乘积并输出。#include void main( ) int i;long sum=1; for(i=1; i=10; i=i+1) sum=sum*i; printf(“the sum of odd is :%l
15、d”,sum);16. 从键盘上输入10个数,求其平均值。 #include void main() int a10,i,s=0; float ave; for(i=0;i10;i+)scanf(“%d”,&ai); for(i=0;i10;i+) sum+=ai; ave=(float)sum/10;printf(ave = %fn, ave); 17、编程序实现求1-1000之间的所有奇数的和并输出。 #include void main( ) int i, sum=0; for(i=1; i1000; i=i+2) sum=sum+i; printf(“the sum of odd is
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 语言 知识 基本 编程
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内