# Clock Math

This is a companion discussion topic for the original entry at https://toph.co/p/clock-math

``````#include <bits/stdc++.h>

using namespace std;

double clockMath(int h, int m){

return (double)(360 - ((30 * h) - (5.5 * m)));
}

int main(){

int h, m;

cin >> h >> m;

double result = clockMath(h, m);
printf("%.7lf\n", result);

return 0;
}
``````

@tariqul You need to â€śdetermine the smaller angle between the two handsâ€ť.

what is the problem with this code

``````#include<stdio.h>
int main()
{
int hr,min;
float x,y;
scanf("%d %d", &hr , &min );
x = min/(float)5;
if(x>hr)
{
y = ((x-hr)*30) - (min/(float)2);
printf("%0.7f",y);
}

if(x<hr)
{
y = ((x+12-hr)*30) - (min/(float)2);
printf("%0.7f",y);
}
}
``````

what if H=3 & M=15 ??
your program is not going to work then.

1 Like

when H=3 and M=15 maybe 7.5 is the result.

DO NOT paste accepted codes in the community. Remove this kind of posts from everywhere.

1 Like

#include <stdio.h>

int main()
{
int H, M;

``````double a;

scanf("%d %d", &H, &M);

a = (double) H - (M/5);

if(a < 0) {
a = (a*(-1)*30) - 0.5*M;
}

else a = a*30 + 0.5*M;

if(a > 180) {
printf("%.7lf\n", 360-a);
}

else printf("%.7lf\n", a);

return 0;
``````

}

What is the problem in this code?
It is getting wrong answer in test case 6.
Can anyone help me?

``````#include <stdio.h>
int main()
{
double angle,i,n,k,m,h;
scanf("%lf",&h);
scanf("%lf",&m);

angle=(11*m/2)-30*h;
i=360-(-1*angle);
if(angle<0 && angle>-180 && m<=60 && h<=12){
printf("%lf\n",angle+(-2*angle));
}
else if(angle<-180 && m<=60 && h<=12){
printf("%lf",i);
}
else if(m<=60 && h<=12){
printf("%lf",angle);
}
return 0;
}
``````

/Why does this source get stuck in test case 4?/