Computer Science, asked by 1804603, 8 months ago

PrepBuddy has an analog clock which consists of two hands one for hour and another for minute. She wants to calculate the shorter angle formed between hour and minute hand at any given time.

Answers

Answered by shivamsakore3901
5

Answer:

analog clock which consists of two hands one for hour and another for minute. She wants to calculate the shorter angle formed between hour and minute hand at any given time.

Explanation:

testCases = int(input())

for i in range(testCases):

 h, m = map(int, input().split()

 h_pos = int( h * 30 + m * 0.5)

 m_pos = int( m * 6)

 if(h_pos - m_pos <= 180):

   angle = int(h_pos - m_pos)

 else:

   angle = int(m_pos - h_pos)

 if(angle < 0):

   angle *= -1  

 print(angle)

Answered by rahulmeetawa
1

Answer:

#include<bits/stdc++.h>

using namespace std;

 

 int main()

 {   int t;

     cin>>t;

   for(int i=1;i<=t;i++){

   int h,m;

   cin>>h>>m;

   double h_angle=(60*h+1*m)/2;

   double m_angle=(h*0+m*6);

   double angle= abs(h_angle-m_angle);

   if(angle<=180){

     cout<<angle;

     cout<<endl;

   }

   else{

     cout<<(360-angle)<<endl;

   }

   }

   return 0;

 }

Explanation:

and also use while and for loop

Similar questions