標籤:java 使用 os io amp 時間 ad ef
C語言實驗一(順序):題目2、圓柱體體積
時間限制(普通/Java):1000MS/3000MS 運行記憶體限制:65536KByte
總提交:494 測試通過:196
描述
請編寫一個程式實現以下要求:
1、輸入圓柱體的半徑(radius)和高(high);
2、定義PI為3.14159;
3、求出圓柱體的體積。
輸入
輸入兩個實數,第一個是圓柱體的半徑,第二個是圓柱體的高。
輸出
輸出有三行:
第一行是圓柱體的半徑;
第二行是圓柱體的高;
第三行圓柱體的體積。
每一個輸出的結果保留到小數點後3位。
範例輸入
3.8 5
3 4
範例輸出
radius:3.800
high:5.000
The volume is:226.823
radius:3.000
high:4.000
The volume is:113.097
提示
使用double類型
#include <stdio.h>
int main()
{ double r,h;
while (scanf("%lf%lf",&r,&h)==2)
{
printf("radius:%.3f\n",r);
printf("high:%.3f\n",h);
printf("The volume is:%.3f\n",3.14159*r*r*h);
}
}
#include <stdio.h>
int main()
{ double r,h,v;
while ( scanf("%lf%lf",&r,&h) !=EOF )
{ v=3.14159*r*r*h;
printf("radius:%.3lf\n",r);
printf("high:%.3lf\n",h);
printf("The volume is:%.3lf\n",v);
}
}
#include<iostream>
#define PI 3.14159
#include<iomanip>
using namespace std;
int main()
{
double radius,high;
while(cin>>radius>>high)
{
cout<<fixed<<setprecision(3)<<"radius:"<<radius<<endl<<"high:"<<high<<endl<<"The volume is:"<<PI*radius*radius*high<<endl;
}return 0;
}
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{ double r,h,v;
while (cin>>r>>h)
{ cout<<fixed<<setprecision(3)<<"radius:"<<r<<endl;
cout<<fixed<<setprecision(3)<<"high:"<<r<<endl;
cout<<fixed<<setprecision(3)<<"The volume is:"
<<3.14159*r*r*h<<endl;
}
return 0;
}