Problem A:平均值
Description
求3个数的平均值。
Input
输入只有一行,为3个较小的整数。
Output
输出为这3个整数的平均值,保留3位小数。
Sample Input
1 2 3
Sample Output
2.000
HINT
注意除法运算对整型数据和浮点型数据是不一样的。
#include <stdio.h>
#include <stdlib.h>
int main()
{
double a,b,c;
scanf("%lf %lf %lf",&a,&b,&c);
printf("%.3lf\n",(a+b+c)/3);
return 0;
}
Problem B: 求圆的面积和周长
Description
从键盘输入圆的半径,求圆的面积和周长,圆周率取3.14。
Input
输入一个浮点型数据,有效数字不会超过十进制的6位。
Output
输出为两行。
第一行为圆的面积,第二行为圆的周长,格式见sample。
Sample Input
3
Sample Output
Area: 28.260000
Perimeter: 18.840000
HINT
了解浮点类型的输入、输出和算术运算符
#include <stdio.h>
#include <stdlib.h>
#define pi 3.14
int main()
{
double r,c,s;
scanf("%lf",&r);
s=pi*r*r;
c=2*pi*r;
printf("Area: %.6lf\n",s);
printf("Perimeter: %.6lf\n",c);
return 0;
}
Problem C: n个数的最大值和最小值
Description
找出n个数中最大的数和最小的数,并将它们的值输出出来。
Input
输入为n+1个整数,都在int类型范围内。这些数可能用若干空格或者换行符分隔开。
输入的第1个数为n,表示后续有n个数输入。从输入的第2个数开始,求出直到第n+1个数中最大的数和最小的数。
Output
输出为两行,格式见sample。
Sample Input
3 0 1 -1
Sample Output
The maximum number is 1.
The minimum number is -1.
HINT
分隔符是空格还是回车都是空白符,对scanf(“%d”)来说没有区别;先读入n,然后用for循环就很容易控制读入n个数的过程。
#include <stdio.h>
int main()
{
int n,i,x,a,b,max,min;
scanf("%d",&n);
scanf("%d",&a);
max=a;
min=a;
for(i=2; i<=n; i++)
{
scanf("%d",&b);
if(b>=max)
max=b;
if(b<=min)
min=b;
}
printf(