[ZA]C语言基本编程题029

上传人:夏** 文档编号:474082005 上传时间:2023-07-08 格式:DOC 页数:16 大小:119.50KB
返回 下载 相关 举报
[ZA]C语言基本编程题029_第1页
第1页 / 共16页
[ZA]C语言基本编程题029_第2页
第2页 / 共16页
[ZA]C语言基本编程题029_第3页
第3页 / 共16页
[ZA]C语言基本编程题029_第4页
第4页 / 共16页
[ZA]C语言基本编程题029_第5页
第5页 / 共16页
点击查看更多>>
资源描述

《[ZA]C语言基本编程题029》由会员分享,可在线阅读,更多相关《[ZA]C语言基本编程题029(16页珍藏版)》请在金锄头文库上搜索。

1、复习题C程序设计编程题1. 输入2个整数,求两数的平方和并输出。#i nclude void mai n() in tta ,b,s;prin tf(please in put a,b:n);scanf(%d%d ” ,&a,&b);s=a*a+b*b;prin tf(the result is %dn,s);2. 输入一个圆半径(r),当r = 0时,计算并输出圆的面积和周长,否则,输出 提示信息。#in clude #defi ne PI 3.14void mai n() floatr ,s , l;prin tf(please in put r:n);scanf(%f ” ,&r);if

2、 (r=0)s=pi*r*r;l=2*i*r ;prin tf(the area is %fn,s);prin tf(the circumfere nee is %fn ,l);elseprin tf(i nput error!n);3. 函数y=f(x)可表示为:2x+1 (x0)编程实现输入一个x值,输出y值。#i nclude void mai n()int x,y; scanf( “%d” ,&x); if(x0)y=2*x-1; else y=0; printf( “ %d”,y);4、编写一个程序 ,从 4个整数中找出最小的数 ,并显示此数。#include void main(

3、) int a,b,c,d,t;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

5、, hisAge;printf(Please enter your 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,

6、 hisAge);error8、键盘输入 2 个加数,再输入答案,如果正确,显示“right ”,否则显示“#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” );elseprintf(“errorn ” );9. 编一程序每个月根据每个月上网进度计算上网费用,计算方法

7、如下:30元费用=每小时3元10小时10 -50小时-50小时要求当输入每月上网小时数,显示该月总的上网费用(6分)每小时2.5元#in clude void mai n() int hour;float fee;printf( “ please in put 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);50元,话费每分 判断哪一种合适。10. 神州行用户无月租费,话费每分钟0.6元,全球通用户月租费钟0. 4元

8、。输入一个月的通话进度,分别计算出两种方式的费用,#in clude void mai n() float a,x,y;printf( n请输入您的话费:”);scanf( “ %f, ”,&a);x= 0.6*a;y=50+0.4*a;printf (神州行话费为n” ,x);printf (全球通话费为n” ,y);if (x=y)printf(建议使用全球通”);else printf(建议使用神州行);11 我所得税计算,应纳税款的计算公式如下:收入税率收入=1000元部分0 %2000元 =收入1000元的部分5 %3000元 =收入2000元的部分10%6000元 =收入3000元

9、的部分15%收入6000元的部分20%输入某人的收入,计算出应纳税额及实际得到的报酬。(7分)(如需连续计算多我的纳税情况,直到输入负数为止,程序应如何改进?试写出程 序)#i nclude“ stdio.h ”void mai n()int grade;float in come,tax,m on ey;printf( “ please in put your in comen”);sca nf (“ f,&in come);if (in come 90,等级 为 A 80 score90,等级为 B。70 w score80,等级为 CC 60 w score70,等级为 D。 score

10、60 ,等级为 E。#include void main()int data;char grade;printf(Please enter the score:); scanf(%d ” , &data);switch(data/10) case 10:case 9 : grade= A ; break;case 8: grade= B ;break;D ;break;E;”,grade);case 7: grade= C;break;case 6: grade=default: grade= printf(the grade is %c*13. 编程设计一个简单的计算器程序。从键盘输入 2个

11、制作数, 1 个运算符,当运 算符为加( +)、减( - )、乘( * )、除( /)时,输出计算结果 #include void 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 + d

12、ata2); break;case -:/*处理减法 */printf(%d - %d = %d n, data1, data2, data1 - data2);break;case *:/*处理乘法 */printf(%d * %d = %d n, data1, data2, data1 * data2); break;case /: /* 处理除法 */if (0 = data2) /*为避免出现溢出不对,检验除数是否为printf(Division by zero!n);elseprintf(%d / %d = %d n, data1, data2, data1 / data2); break;default: printf(Unknown operator! n);14. 从键盘输入 10 个整数,统计其中正数、负数和零的个数,并在屏幕上输出。 #include void main( )int a10, i,p=0,n=0,z=0;printf( “ please input number ” ); for(i=0;i10;i+) scanf( “

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 办公文档 > 活动策划

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号