C语言编写一程序,输入一个圆的半径,计算并输出该圆的周长于面积。在线等,悬赏50,立即采纳!

编写一程序,输入一个圆的半径,计算并输出该圆的周长于面积。要求:用符号常量PI表示3.14159;周长和面积输出时保留小数点后两位数字。

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#define PI 3.14159
int main()
{
    float r;
    scanf("%g",&r);
    double s=PI*r*r;
    double c=2*PI*r;
    printf("%.*lf\n",2,c);
    printf("%.*lf",2,s);
    return 0;
}

温馨提示:答案为网友推荐,仅供参考
第1个回答  2015-03-09
#include<stdio.h>
#define PI 3.14159
int main()
{
    float r, l, s;
    scanf("%f", &r);
    printf("S: %.2f\n", PI*r*r);
    printf("L: %.2f\n", 2*PI*r);
    return 0;
}

第2个回答  2015-03-09
#include<iostream>
#include<iomanip>
using namespace std;
#define PI 3.14159
int main()
{
double r;
cin >> r;
cout <<setprecision(2)<<fixed<< 2 * PI*r << endl;
cout << PI*r*r << endl;

return 0;
}

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网