system
November 12, 2018, 4:28pm
1
Given a time (hours as H and minutes as M), determine the smaller angle between the two hands of a c…
Click here to read the complete problem statement.
If you need help solving this problem, mention your approach and ask specific questions. Please avoid sharing your code and asking the Community to figure out “what’s wrong”.
Why I’m getting wrong answer???
#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;
}
hjr265
January 15, 2019, 6:43pm
3
@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);
}
}
tanzid
April 25, 2019, 6:07am
5
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.
#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? /
def mainangle(h, m):
if h < 0 or m < 0 or h > 12 or m > 60:
print('Wrong input')
if h == 12:
h = 0
if m == 60:
m = 0
hour_angle = 0.5 * (h * 60 + m)
minute_angle = 6 * m
angle = abs(hour_angle - minute_angle)
angle = min(360 - angle, angle)
if angle >= 180:
angle = (360-angle)
return angle
H = int(input())
M = int(input())
print('Angle', mainangle(H, M), 'degree')
what wrong this code?
Could someone please help me out with this code? I don’t know why it isn’t working.
time = input("Enter the time")
hours = int(time[0:2])
minutes = int(time[-2:])
if hours == 0 and minutes == 0:
Answer = 0
else:
HoursAngle1 = hours * 30
HoursAngle2 = minutes * 0.5
HoursAngle = HoursAngle1 + HoursAngle2
MinuteAngle = minutes * 6
if HoursAngle > MinuteAngle:
Answer = (HoursAngle - MinuteAngle)
else:
Answer = (MinuteAngle - HoursAngle)
if Answer > 180:
Answer = 360 -((HoursAngle - MinuteAngle))
print("%.7f" % Answer, "degrees")