C语言练习题〔山东科技大学吐血整理〕
数学11-1 C语言平时训练题
1、算术基本运算
Description
计算两整数x和y(0
Input
输入只有一行。
Output
输出为多行,按顺序每行输出x,y的和、差、积、商、余数、x的平方和y的三次方
Sample Input
x = 11, y = 3
Sample Output
x + y : 14
x - y : 8
x * y : 33
x / y quotient: 3, remainder: 2
x ^ 2 : 121
y ^ 3 : 27
Answer
#include
int main()
{
int x,y,a,b,c,d,e,f,g;
0
scanf("x = %d, y = %d",&x,&y);
a=x+y;
b=x-y;
c=x*y;
d=x/y;
e=x%y;
f=x*x;
g=y*y*y;
printf("x + y : %d\n",a);
printf("x - y : %d\n",b);
printf("x * y : %d\n",c);
printf("x / y quotient: %d, remainder: %d\n",d,e);
printf("x ^ 2 : %d\n",f);
printf("y ^ 3 : %d\n",g);
return 0;
}
2、求圆的面积和周长
Description
从键盘输入圆的半径,求圆的面积和周长,圆周率取3.14。
Input
输入一个浮点型数据,有效数字不会超过十进制的6位。
Output
输出为两行。第一行为圆的面积,第二行为圆的周长,格式见sample。
Sample Input
3
Sample Output
Area: 28.260000
Perimeter: 18.840000
#include
#define PI 3.14
int main()
{
float r,s,c;
scanf("%f",&r);
s=PI*r*r;
c=2*PI*r;
printf("Area: %f\n",s);
printf("Perimeter: %f\n",c);
return 0;
}
3、 平均值
Description
求3个数的平均值。
Input
输入只有一行,为3个较小的整数。
Output
输出为这3个整数的平均值,保留3位小数。
Sample Input
1 2 3
Sample Output
2.000
#include
int main()
{
int a,b,c;
float d;
scanf("%d %d %d",&a,&b,&c);
d=(a+b+c)/3.0;
printf("%.3f\n",d);
return 0;
}
4、货币兑换
Description
给出人民币对美元、欧元、日元的当日汇率,求给定金额的人民币能兑换成外币的金额,求给定金额的外币能兑换成人民币的金额。要计算的外币有三种:美元、欧元、日元。
Input
输入有三行。第一行依次为美元、欧元、日元外币汇率,用空格分开。汇率用100外币为单位,精确到小数点后4位,如668.5200表示“100美元=668.5200人民币”。汇率浮动范围为(0,10000)。第二行为外币金额x,第三行为人民币金额y。x,y均为整数,且0
Output
输出为两行。第一行为金额为x的美元、欧元、日元兑换成人民币的金额,用空格分开。第二行为金额为y的人民币兑换成美元、欧元、日元的金额,用空格分开。所有金额精确到小数点后两位。
Sample Input
668.5200 908.0685 7.9852
1500
1500
Sample Output
10027.80 13621.03 119.78
224.38 165.19 18784.75
#include
int main()
{
double x,y,a,b,c,d,e,f,g,h,i;
scanf("%lf%lf%lf",&a,&b,&c);
scanf("%lf",&x);
scanf("%lf",&y);
d=x/100*a;
e=x/100*b;
f=x/100*c;
g=y/a*100;
h=y/b*100;
i=y/c*100;
printf("%.2lf %.2lf %.2lf\n",d,e,f);
printf("%.2lf %.2lf %.2lf\n",g,h,