2022年C语言基本编程题.docx





《2022年C语言基本编程题.docx》由会员分享,可在线阅读,更多相关《2022年C语言基本编程题.docx(32页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -复习题C 程序设计编程题1. 输入 2 个整数,求两数的平方和并输出;#include void main intt a ,b,s; printfplease input a,b:n; scanf%d%d ” ,&a,&b; s=a*a+b*b; printfthe result is %dn,s; 2. 输入一个圆半径(提示信息;r ),当 r 0 时,运算并输出圆的面积和周长,否就,输出#include #define PI 3.14 void main float r ,s , l; printfple
2、ase input r:n; scanf%f” ,&r; if r=0 s=pi*r*r; l=2*i*r ; printfthe area is %fn,s; printfthe circumference is %fn,l; else printfinput error.n; 3、函数 y=fx 可表示为: 2x+1 x0 第 1 页 共 17 页细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 1 页,共 17 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -编程实现输
3、入一个 x 值,输出 y 值;#include void main int x,y; scanf “ %d” ,&x; ifx0 y=2*x-1; else y=0; printf“ %d” ,y;, 并显示此数;4、编写一个程序, 从 4 个整数中找出最小的数#include void main 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 时
4、, y=3,当 x=0 时 y=5,编程,从键盘输入一个 x 值,输出 y 值;#include void main int x,y; scanf%d,&x; if x0 y=1; else ifx=0 y=5; else y=3; printfx=%d,y=%dn,x,y; 6从键盘输入两个数,求出其最大值(要求使用函数完成求最大值,并在主函数中 调用该函数)第 2 页 共 17 页细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 2 页,共 17 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - -
5、 - - - - - -#include float maxfloat x,float y; void main float a,b,m; scanf%f,%f,&a,&b; m=maxa,b; printfMax is %fn,m; float maxfloat x,float y float temp; if xy temp=x; x=y; y=temp; returnx; 7、从键盘输入你和你伴侣的年龄,编成判定谁的年龄最大,并打印最大者的年龄;#include void main int yourAge, hisAge; printfPlease enter your age:; sc
6、anf%d, &yourAge; /*输入你的年龄yourAge*/ printfPlease enter your friends age:; scanf%d, &hisAge; /*输入你伴侣的年龄hisAge*/ if yourAge = hisAge printfYou are older. Your age is = %dn, yourAge; if hisAge yourAge printfYour friend is older. HisAge age is = %dn, hisAge; 8、键盘输入2 个加数,再输入答案,假如正确,显示“right” ,否就显示“error ”
7、#include “ stdio.h”void main 第 3 页 共 17 页细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 3 页,共 17 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -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“
8、 rightn” ; else printf“ errorn” ; 9. 编一程序每个月依据每个月上网时间运算上网费用,运算方法如下:30 元 10 小时费用 每小时 3 元 10 50 小时每小时 2 . 5 元 50 小时要求当输入每月上网小时数 , 显示该月总的上网费用 6 分 #include void main int hour; float fee; printf“ please input hour:n” ; scanf“ %d” ,&hour; ifhour=10&hour=50 fee=3*hour; else fee=hour*2.5; printf“ The total
9、fee is %f”,fee; 10. 神州行用户无月租费,话费每分钟0.6 元,全球通用户月租费50 元,话费每分钟 0. 4 元;输入一个月的通话时间,分别运算出两种方式的费用,判定哪一种合适;#include void main float a,x,y; printf“ n 请输入您的话费:”; scanf“ %f, ” ,&a; 第 4 页 共 17 页细心整理归纳 精选学习资料 - - - - - - - - - - - - - - - 第 4 页,共 17 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -
10、 x= 0.6*a; y=50+0.4*a; printf “ 神州行话费为n” ,x;printf “ 全球通话费为n” ,y;if x=y printf“ 建议使用全球通”; else printf“ 建议使用神州行; 11个人所得税运算,应纳税款的运算公式如下:收入 税率收入 收入 1000 元的部分 53000 元收入 2000 元的部分 106000 元收入 3000 元的部分 15收入 6000 元的部分 20输入某人的收入,运算出应纳税额及实际得到的酬劳;(7 分)(如需连续运算多个人的纳税情形,直到输入负数为止,程序应如何改进?试写出程序)#include “ stdio.h”
11、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=intincome/1000; switchgrade case 0 : tax=0;break; case 1 : tax=income-1000*0.05;break; case 2 : tax=50+income-2000*0.1;break; 第 5 页 共 17 页细心整理归纳
12、 精选学习资料 - - - - - - - - - - - - - - - 第 5 页,共 17 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - - case 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 ,按以下原就输出其等级
13、:score 90,等级 为 A;80score90 ,等级为 B;70score80 ,等级为 C; 60score70 ,等级为 D;score60 ,等级为 E; #include void main int data; char grade; printfPlease enter the score:; scanf%d ” , &data; switchdata/10 case 10: case 9 : grade=A; break; case 8: grade=B; break; case 7: grade=C; break; case 6: grade=D; break; defa
14、ult: grade=E; printfthe grade is %c” ,grade; *13. 编程设计一个简洁的运算器程序;从键盘输入2 个操作数, 1 个运算符,当运算符为加( +)、减( - )、乘( * )、除( / )时,输出运算结果 #include void main int data1, data2; /*定义两个操作符*/ char op; /*定义运算符 */ printfPlease enter the expression:; scanf%d%c%d, &data1, &op, &data2; /*输入运算表达式*/ 第 6 页 共 17 页细心整理归纳 精选学习资
15、料 - - - - - - - - - - - - - - - 第 6 页,共 17 页 - - - - - - - - - 名师归纳总结 精品学习资料 - - - - - - - - - - - - - - -switchop /*依据输入的运算符确定要执行的运算*/ case +: /* 处理加法 */ printf%d + %d = %d n, data1, data2, data1 + data2; break; case -: /* 处理减法 */ printf%d - %d = %d n, data1, data2, data1 - data2; break; case *: /*
16、 处理乘法 */ printf%d * %d = %d n, data1, data2, data1 * data2; break; case /: /*处理除法 */ 0*/ if 0 = data2 /*为防止显现溢出错误,检验除数是否为printfDivision by zero.n; else printf%d / %d = %d n, data1, data2, data1 / data2; break; default: printfUnknown operator. n; 14. 从键盘输入 10个整数,统计其中正数、负数和零的个数,并在屏幕上输出;#include void m
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 2022 语言 基本 编程

限制150内