fork download
  1. #include <iostream>
  2. #include <cmath>
  3.  
  4. const double PI = 3.14159265358979323846;
  5.  
  6. int main() {
  7. double alpha, beta;
  8.  
  9. // Input angles in radians
  10. std::cout << "Enter angle α (for the hour hand) in radians ((2π radians corresponds to 12 hours)): ";
  11. std::cin >> alpha;
  12.  
  13. std::cout << "Enter angle β (for the minute hand) in radians (60 minutes corresponds to 2π radians): ";
  14. std::cin >> beta;
  15.  
  16. // Calculate the angle difference between the hands
  17. double angleDifference = std::abs(alpha - beta);
  18.  
  19. // Finding the smaller angle between the hands
  20. if (angleDifference > PI) {
  21. angleDifference = 2 * PI - angleDifference;
  22. }
  23.  
  24. // Convert angle to hours and minutes
  25. double hours = (alpha * 12) / (2 * PI); // Convert alpha to hours
  26. double minutes = (beta * 60) / (2 * PI); // Convert beta to minutes
  27.  
  28. // Output results
  29. std::cout << "Angle between the hands: " << angleDifference << " radians\n";
  30. std::cout << "Number of hours: " << static_cast<int>(hours) << "\n";
  31. std::cout << "Number of full minutes: " << static_cast<int>(minutes) << "\n";
  32.  
  33. return 0;
  34. }
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
Enter angle α (for the hour hand) in radians ((2π radians corresponds to 12 hours)): Enter angle β (for the minute hand) in radians (60 minutes corresponds to 2π radians): Angle between the hands: 2.2854e-310 radians
Number of hours: 0
Number of full minutes: 0