已知一个圆的半径,计算该圆的周长和面积,结果保留2位小数。半径用实数表示,由键盘输入。设圆周率等于3.14159。
输入格式:
输入在一行中给出1个实数r,表示圆的半径。
输出格式:
在一行中输出圆的周长和面积,结果保留2位小数。数据之间留一个空格。
输入样例:
3
输出样例:
18.85 28.27
代码长度限制
16 KB
时间限制
400 ms
内存限制
64 MB
思路:
面积=半径的平方*π
周长=2πr=πd
对于PI(π)的定义可以使用宏定义也可以在主函数里面定义,两者没有差别。
#include<stdio.h>
#include<math.h>
#define pi 3.14159
int main()
{
double r,c,s;
scanf("%lf",&r);
c=2*pi*r;
s=pi*pow(r,2);
printf("%.2lf %.2lf\n",c,s);
}
#include<stdio.h>
#include<math.h>
int main()
{
double r,c,s, pi=3.14159;
scanf("%lf",&r);
c=2*pi*r;
s=pi*pow(r,2);
printf("%.2lf %.2lf\n",c,s);
}