作者steve1012 (steve)
看板NTUBIME103HW
标题[普物] 实验一的个别g值计算
时间Sat Oct 30 19:03:23 2010
因为打个别的数值套用公式非常麻烦要按很久==
所以就弄了一个程式
下面很长复制到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)
1F:推 sky2857:其实用excel可能会比较快一点XD 10/30 19:31
2F:→ steve1012:其实我不会用excel QQ我找不到函数要怎麽弄 10/30 20:46
3F:推 sky2857:全部打成程式根本太神了XD 10/30 21:17
4F:推 ss355227:这不是普物吧XDD 10/30 22:13
5F:→ steve1012:这是拿来算普物的! 10/30 22:24