Read the problem statement here: https://practice.geeksforgeeks.org/problems/angle-between-hour-and-minute-hand/0

To solve this we have to keep two things in mind. First, hour hand completes 360 degrees in 12 hours.

360 degrees in (60 * 12) minutes = 720 minutes
Then how many degrees in one minute = 360 / 720 degrees = 0.5 degrees

Second, minute hand completes 360 degrees in one hour i.e. 60 minutes

360 degrees in 60 minutes
1 minute = 360 / 60 degrees = 6 degrees

Remember, there are two corner cases too. Set both hour and minute to zero when their value is 12 and 60 respectively.

C++ code:

#include<iostream>
#include <cmath>
using namespace std;
double findAngle(double h, double m){
double angle;
//corner cases
if(h == 12)
h=0;
if(m == 60)
m=0;
double hour_angle = (h * 60 + m) * 0.5;
double min_angle = m * 6;
angle = abs(hour_angle - min_angle);
angle = min(360 - angle, angle);
return angle;
}
int main() {
int t;
double h, m;
scanf("%d", &t);
while(t--){
scanf("%lf %lf", &h, &m);
printf("%.f\n", floor(findAngle(h, m)));
}
return 0;
}

Read this interesting article on clocks – Maths around the clock.