看板 NTUBIME103HW 關於我們 聯絡資訊
因為打個別的數值套用公式非常麻煩要按很久== 所以就弄了一個程式 下面很長複製到c++裡面運行 依序輸入實驗一的p1p2值 (cin>> 第一個p1 p2 cin>>第二個 p1 p2) 可以幫你算出個別的g值 有想要分析這幾個g值的人可以用用看囉 #include "stdafx.h" #include "iostream" #include "math.h" #include "iomanip" using namespace std; long double gravity_computation(long double,long double); int _tmain(int argc, _TCHAR* argv[]) { double arr[5][2]={0}; double arr_g[5]={0}; int i=0; int j=0; const long double pi=3.14159265358979; for(i=0;i<=4;i++) { for(j=0;j<=1;j++) { cout<<"please enter p"<<(j+1)<<endl; cin>>arr[i][j]; } } cout<<setw(8)<<" P1\t \t P2"<<endl; for(i=0;i<=4;i++) { for(j=0;j<=1;j++) {cout<<setw(8)<<arr[i][j]<<"\t";} cout<<endl; } cout<<setw(8)<<setprecision(6)<<gravity_computation(1.9986,1.9682)<<endl; for(i=0;i<=4;i++) { long double x=0; long double y=0; for(j=0;j<=1;j++) { switch (j) { case 0: x=arr[i][j]; break; case 1: y=arr[i][j]; break; } } cout<<x<<"\t"<<y<<endl; arr_g[i]=gravity_computation(x,y); } cout<<setw(8)<<"the value of gravity is"<<endl; for(i=0;i<=4;i++) { cout<<setw(8)<<(i+1)<<" "<<arr_g[i]<<endl; } system("pause"); return 0; } long double gravity_computation(long double x,long double y) { long double g; const long double pi=3.14159265358979; g=8*pi*pi/((x*x+y*y)/100+(x*x-y*y)/50); return g; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 118.161.78.159 ※ 編輯: steve1012 來自: 118.161.78.159 (10/30 19:04)
sky2857:其實用excel可能會比較快一點XD 10/30 19:31
steve1012:其實我不會用excel QQ我找不到函數要怎麼弄 10/30 20:46
sky2857:全部打成程式根本太神了XD 10/30 21:17
ss355227:這不是普物吧XDD 10/30 22:13
steve1012:這是拿來算普物的! 10/30 22:24