没有合适的资源?快使用搜索试试~ 我知道了~
(完整版)计算机程序设计基础(C语言)编程习题.doc
1 下载量 82 浏览量
2022-11-15
15:19:30
上传
评论 1
收藏 120KB DOC 举报
温馨提示
试读
17页
(完整版)计算机程序设计基础(C语言)编程习题.doc
资源推荐
资源详情
资源评论
(完整版)计算机程序设计基础(C 语言)编程习题
1
计算机程序设计基础(C 语言)
编程练习题及参考答案
1.输入 2 个整数,求两数的平方和并输出。
#include <stdio.h>
main()
{ intt a ,b,s;
printf(”please input a,b:");
scanf("%d%d",&a,&b);
s=a*a+b*b;
printf("the result is %d”,s);
}
2。 输入一个圆半径(r)当 r>=0 时,计算并输出圆的面积和周长,否则,输出提示信息.
#include 〈stdio.h>
#define PI 3。14 〈stdio。h〉
main()
{ float r ,s , l;
printf("please input r:”);
scanf(”%f”,&r);
if (r〉=0)
{s=pi*r*r;
l=2*i*r ;
printf("the area is %f”,s);
printf("the circumference is %f”,l);}
else
printf(”input error!");
}
3、函数 y=f(x)可表示为:
2x+1 (x<0)
y= 0 (x=0)
2x—1 (x〉0)
编程实现输入一个 x 值,输出 y 值。
main()
{int x,y;
scanf(“%d",&x);
If(x〈0)y=2*x+1;
If(x〉0)y=2*x-1;
If(x==0) y=0;
printf(“%d”,y);}
4、编写一个程序,从 4 个整数中找出最小的数,并显示此数。
main( )
{int a,b,c,d,t;
scanf (“%d,%d,%d,%d ”,&a,&b,&c,&d);
if (a>b)
{t=a; a=b; b=t;}
if (a〉c)
(完整版)计算机程序设计基础(C 语言)编程习题
2
{t=a; a=c; c=t;}
if (a>d)
{t=a; a=d; d=t;}
printf (“min = %d \n”,a);
}
5.有一函数当 x〈0 时 y=1,当 x>0 时,y=3,当 x=0 时 y=5,编程,从键盘输入一个 x 值,输出 y 值.
main()
{int x,y;
scanf("%d",&x);
if (x<0) y=1;
else if(x==0) y=5;
else y=3;
printf("x=%d,y=%d\n”,x,y);}
6.从键盘输入两个数,求出其最大值(要求使用函数完成求最大值,并在主函数中调用该函数)
main()
{float max(float x,float y);
float a,b,m;
scanf(”%f,%f",&a,&b);
m=max(a,b);
printf("Max is %f\n",m);
}
float max(float x,float y)
{
float temp;
if (x<y)
{temp=x;
x=y;
y=temp;
}
return(x);
}
7、从键盘输入你和你朋友的年龄,编成判断谁的年龄最大,并打印最大者的年龄。
#include 〈stdio.h>
main()
{ int yourAge, hisAge;
printf(”Please enter your age:");
scanf("%d", &yourAge); /*输入你的年龄 yourAge*/
printf(”Please enter your friend's age:”);
scanf("%d", &hisAge); /*输入你朋友的年龄 hisAge*/
if (yourAge >= hisAge)
{
printf("You are older! Your age is = %d\n", yourAge);
}
if (hisAge > yourAge)
{
printf(”Your friend is older! HisAge age is = %d\n”, hisAge);
(完整版)计算机程序设计基础(C 语言)编程习题
3
}}
8、键盘输入 2 个加数,再输入答案,如果正确,显示“right”,否则显示“error”
#include “stdio.h"
main( )
{int a,b,c;
printf(“please input a and b\n”);
scanf (%d,%d”,&a,&b);
printf(“please input the answer for a+b\n”);
scanf (%d”,&c);
if (c==a+b)
printf(“right\n”);
else
printf(“error\n”);
}
9. 编一程序每个月根据每个月上网时间计算上网费用,计算方法如下:
�
�
�
�
�
�
�
�
�
小时
小时
小时
元每小时
元每小时
元
费用
50
5010
10
5.2
3
30
要求当输入每月上网小时数,显示该月总的上网费用(6 分)
main()
{ int hour;
float fee;
printf(“please input hour:\n”);
scanf(“%d”,&hour);
if(hour<=10)
fee=30;
else 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 元。输入一个
月的通话时间,分别计算出两种方式的费用,判断哪一种合适。
main()
{float a,x,y;
printf(“\n 请输入您的话费:”);
scanf(“%f,”,&a);
x= 0。6*a;
y=50+0.4*a;
printf (“神州行话费为: %f\n",x);
printf (“全球通话费为: %f\n”,y);
if (x〉=y)
printf(“建议使用全球通");
else printf(“建议使用神州行);
}
(完整版)计算机程序设计基础(C 语言)编程习题
4
11.个人所得税计算,应纳税款的计算公式如下:
收入
税率
收入〈=1000 元部分
0%
2000 元〉=收入〉1000 元的部分
5%
3000 元〉=收入>2000 元的部分
10%
6000 元>=收入>3000 元的部分
15%
收入〉6000 元的部分
20%
输入某人的收入,计算出应纳税额及实际得到的报酬。(7 分)
(如需连续计算多个人的纳税情况,直到输入负数为止,程序应如何改进?试写出程序)
#include “stdio.h”
main()
{
int grade;
float income,tax,money;
printf(“please input your income\n”);
scanf (“%f",&income);
if (income〈0)
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;
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,按下列原则输出其等级:score≥90,等级为 A;80≤score<90,
等级为 B;70≤score<80,等级为 C;60≤score<70,等级为 D;score〈60,等级为 E.
#include 〈stdio。h>
main()
{
int data;
char grade;
printf(”Please enter the score:");
scanf(”%d”, &data);
switch(data/10)
{ case 10:
case 9 : grade='A’; break;
剩余16页未读,继续阅读
资源评论
yyyyyyhhh222
- 粉丝: 411
- 资源: 6万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功