Anonymous
Anonymous asked in 電腦與網際網路程式設計 · 1 decade ago

# 請問這個c 程式的意思

#include "stdafx.h"

#include <iostream>

using namespace std;

int main(int argc, char* argv[])

{

const double pi =3.1416;

double r = 0.0 ;

double area = 0.0;

double length = 0.0;

cout << endl

<< "Please input n \? ";

cin >> r;

area = pi * r * r;

length = 2.0 * pi * r;

cout << endl

<< "area : " << area ;

cout << endl

<< "length : " << length;

cout << endl;

}

Rating
• 1 decade ago

#include "stdafx.h" <==載入函式庫

#include <iostream> <==載入函式庫

using namespace std;

int main(int argc, char* argv[])

<==argc 參數總和，代表包括指令本身的參數個數。系統會自動計算所輸入的參數個數。

<==argv 參數值。也就是使用者在命令列中輸入的字串，每個字串以空白相隔。自動將程式本身的名稱指定給argv[0]，再將程式名稱後面所接續的參數依序指定給argv[1]、argv[2]&hellip;.。

{ <==表主程式開始

const double pi =3.1416; <==const常數之意，即指定pi為一常數3.1416；double指雙精確度浮點數

double r = 0.0 ; <==定義r,area,length為雙精度浮點數

double area = 0.0;

double length = 0.0;

cout << endl <==表換行

<< "Please input n ? "; <==輸出(顯示出)Please input n ?

cin >> r; <==表輸入之值為r（此處r為半徑）

area = pi * r * r; <==計算：面積(area)=圓周率(pi)乘上半徑(r)平方

length = 2.0 * pi * r; <==計算：周長(length)=2*r(即兩倍半徑，直徑)*圓周率(pi)

cout << endl <==表換行

<< "area : " << area ; <==輸出："area:"和area(剛剛計算的)

cout << endl <==表換行

<< "length : " << length; <==輸出："length:"和lendth(剛剛計算的)

cout << endl; <==表換行

} <==程式結束

Source(s): 自己