Implement a C++ function which, when given the length of a simple pendulum in meters,
returns the period of oscillation in seconds, i.e.
period of oscillation = 2 π (length / g)
where Standard Gravity, g = 9.80665 metres/sec2
Implement a main function which reads the pendulum length, calls the above function and
prints the result. A pendulum of length 1 meter has a period of 2.006409 seconds.
#define _USE_MATH_DEFINES
#include <iostream>
#include <math.h>
using namespace std;
double func(double length){
double g=9.80665;
double period=2*M_PI*(sqrt(length / g));
return period;
}
int main()
{
double length;
cout<<"\nEnter length: ";
cin>>length;
cout<<"\nPeriod of oscillation= "<<func(length);
return 0;
}
Output
Comments
Leave a comment