編寫一個c++程式,從鍵盤輸入圓的半徑,輸出圓的周長和面積

編寫一個c++程式,從鍵盤輸入圓的半徑,輸出圓的周長和面積


(法1)#include
using namespace std;
#define PI 3.1415926
class Circle
{
double r;
public:
Circle(double R=0)
{
r=R;
}
void Get()
{
coutr;
}
void cal()//計算圓的周長和半徑
{
cout



使用java,從鍵盤輸入圓的半徑,求圓的周長和圓的面積並輸出?


importjavax.swing.JOptionPane;public class yuan{ public static void main(String args[]){ double p,s,l,r;String str;//其中s為面積,l為周長,r為半徑p=3.1415;str=JOptionPane.showInputDialog(“請輸…



求程式設計,從鍵盤輸入圓的半徑,求該圓的周長和面積下麵是我做的,
#include
void main()
{
float pi=3.14;
int s,l,r;
scanf(“%d \ n”,& r);
s=pi*r*r;
l=2*pi*r;
printf(%d%d\n“,l,s);
}


r、s和l變數建議定義成float或double類型,另外出於養成良好的習慣,最好是將π定義成常數const
輸入建議scanf(“%f \ n”,& r);
輸出建議使用printf(%f\n%f\n“,l,s);
不然的話,只能計算整數,功能不强,精度太低