Given Hours h and Rotations r. The task is to calculate the IST (Indian Standard Time) . IST (Indian Standard Time) is the time observed throughout India, with a time offset of UTC/GMT + 05:30. UTC (Coordinated Universal Time) is a 24-hour time standard that is used to synchronize world clocks.
Examples :
Input : h = 24 , r = 82.50 Output : IST = 5:30 IST = (24/360)* 82.50 = 5.5 = 0.5*60 (i.e 60 minute = 360 degree rotation and 1 minute = 6 degree so, 0.5 minute * 60 = 30) IST = 5:30 Input : h=20 , r=150 Output : IST = 8:20
Approach :
As we know , 60 minute = 360 degree rotation 60 minute = 1 hour so, 1 hour = 360 degree rotations 1 degree rotation = 1 (hour ) / 360 2 degree rotation = (1(hour) /360) * 2 So, Generalisation formula (for IST) = UTC + (h(hour)/ 360 ) * r (UTC = 0 for IST ) = (h(hour)/ 360 ) * r Answer will be convert in 0:00 form so int part(hour) and float part in IST is separated and in float part multiplied by 60 to convert it into minute.
Implementation :
#include <iostream>
#include <cmath>
using namespace std;
// function to return IST
void cal_IST(int h,float r)
{
float IST = (h* r)/360;
// separate integer part
int int_IST = (int)IST;
//separate float part and return ceil value
int float_IST = ceil((IST - int_IST) * 60);
cout<<int_IST<<":"<<float_IST;
}
int main() {
int h = 20;
float r = 150;
cal_IST(h,r);
}