Wednesday, 22 April 2015

C++ Program to calculate 'g' from experimental data - Simple pendulum















PROGRAM

#include<iostream>
#include<math.h>
using namespace std;
int main()
{
int i,n;
float l[10],t1[10],t2[10],t[10],r[10],s=0,m,g;
cout<<"Enter the no.of trial:";
cin>>n;
for(i=0;i<n;i++)
{
cout<<"\nEnter the value of L:";
cin>>l[i];
cout<<"\nEnter the value of T1:";
cin>>t1[i];
cout<<"\nEnter the value of T2:";
cin>>t2[i];
t[i]=(t1[i]+t2[i])/(2*20);
r[i]=l[i]/(pow(t[i],2));
cout<<"\nValue of (L/T^2) is:"<<r[i]<<"\n\n";
s=s+r[i];
}
m=s/n;
g=4*pow(3.14,2)*m;
cout<<"\n";
cout<<"\nLength\t\tPeriod\t\t(L/T^2)\n";
for(i=0;i<n;i++)
{
cout<<"\n\n"<<l[i]<<"\t\t"<<t[i]<<"\t\t"<<r[i];    

cout<<"\n\nMean value of (L/T^2) is: "<<m;
cout<<"\nAcceleration due to gravity,g: "<<g<<" m/s^2\n\n";
return 0;
}




OUTPUT

Enter the no.of trial:8

Enter the value of L:.50

Enter the value of T1:28.3

Enter the value of T2:28.4

Value of (L/T^2) is:0.248842


Enter the value of L:.60

Enter the value of T1:31

Enter the value of T2:31.2

Value of (L/T^2) is:0.248136


Enter the value of L:.70

Enter the value of T1:33.5

Enter the value of T2:33.6

Value of (L/T^2) is:0.248756


Enter the value of L:.80

Enter the value of T1:35.8

Enter the value of T2:35.9

Value of (L/T^2) is:0.248984


Enter the value of L:.90

Enter the value of T1:38

Enter the value of T2:38.1

Value of (L/T^2) is:0.248653


Enter the value of L:1.00

Enter the value of T1:40

Enter the value of T2:40.1

Value of (L/T^2) is:0.249376


Enter the value of L:1.10

Enter the value of T1:42.1

Enter the value of T2:42.1

Value of (L/T^2) is:0.24825


Enter the value of L:1.20

Enter the value of T1:43.8

Enter the value of T2:44

Value of (L/T^2) is:0.249065



Length Period (L/T^2)


0.5 1.4175 0.248842

0.6 1.555 0.248136

0.7 1.6775 0.248756

0.8 1.7925 0.248984

0.9 1.9025 0.248653

1 2.0025 0.249376

1.1 2.105 0.24825

1.2 2.195 0.249065

Mean value of (L/T^2) is: 0.248758
Acceleration due to gravity,g: 9.81061 m/s^2

No comments :

Post a Comment

Related Posts Plugin for WordPress, Blogger...