Answer to Question #233124 in C++ for alex

Question #233124

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.


1
Expert's answer
2021-09-07T15:41:11-0400
#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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS