fork(1) download
  1. #include <iostream>
  2. #include <cmath> // for sqrt() and M_PI
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. double L, g, T;
  8.  
  9. // Input values
  10. cout << "Enter the length of the pendulum (L in meters): ";
  11. cin >> L;
  12.  
  13. cout << "Enter the acceleration due to gravity (g in m/s^2): ";
  14. cin >> g;
  15.  
  16. // Formula: T = 2 * pi * sqrt(L / g)
  17. T = 2 * M_PI * sqrt(L / g);
  18.  
  19. // Output result
  20. cout << "The time period of the simple pendulum is: " << T << " seconds" << endl;
  21.  
  22. return 0;
  23. }
Success #stdin #stdout 0.01s 5288KB
stdin
8
9
stdout
Enter the length of the pendulum (L in meters): Enter the acceleration due to gravity (g in m/s^2): The time period of the simple pendulum is: 5.92384 seconds