C语言基本编程题

上传人:m**** 文档编号:498180314 上传时间:2024-02-29 格式:DOCX 页数:17 大小:38.03KB
返回 下载 相关 举报
C语言基本编程题_第1页
第1页 / 共17页
C语言基本编程题_第2页
第2页 / 共17页
C语言基本编程题_第3页
第3页 / 共17页
C语言基本编程题_第4页
第4页 / 共17页
C语言基本编程题_第5页
第5页 / 共17页
点击查看更多>>
资源描述

《C语言基本编程题》由会员分享,可在线阅读,更多相关《C语言基本编程题(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),当r=0时,计算并输出圆的面积和周长,否则,输出 提示信息。#include #define PI 3.14 void main() float r ,s , l; printf(please input r:n); scanf(%f ,&r);if (r=0) s=pi*

2、r*r;l=2*i*r ;printf(the area is %fn,s);printf(the circumference is %fn,l); elseprintf(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 e

5、nter 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, 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.编一程序每个月根据每个月上网时间计算上网费用,计算方法如下:30元M10小时费用=每小时3元10-50小时小时2.5元之50小时要求当输入每月

7、上网小时数,显示该月总的上网费用(6分)#include void main() 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

8、 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元的部分15%收入6000元的部分20%输入某人的收入,计算出应纳税额及实际得到的报酬。(7分)(如需连续计算多

9、个人的纳税情况,直到输入负数为止,程序应如何改进?试写出程序)#include “stdio.h void main()int grade;float income,tax,money;printf( please input your incomen );scanf (%f,&income);if (income90,等级 为 A 80Wscore90 ,等级为 B; 70 score80 ,等级为 C; 60 score70 ,等级为 D; score60 ,等级为E。#include void main() int data;char grade;printf(Please enter

10、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 void ma

11、in() 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, data1

12、- data2);break;case *:/*处理乘法 */printf(%d * %d = %d n, data1, data2, data1 * data2);break;case /:/*处理除法 */if (0 = data2) /* 为避免出现溢出错误,检验除数是否为 0*/ 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;i0)p+;e

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

最新文档


当前位置:首页 > 商业/管理/HR > 营销创新

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