-
The program calculates the angle between the two needles at any time between 0:00 and 23:59.
#include
#include
int main()
int m,h;
float a,a1,a2;
scanf("%d%d",&h,&m);
a1=h%12*30+;The hour hand is 30 degrees for every 1 hour, and the 1 minute walk is a2=6*m; The minute hand is 6 degrees a=fabs (a1-a2) every 1 minute walked; The included angle is the absolute value of printf("at %d:%d the angle is %.1f degrees.
n",h,m,a);
return 0;
-
How to solve the angle problem:
#include
void main()
int a,b;
float c,d,e;//
scanf("%d%d",&a,&b);
c=(a%12+(float)b/60)*30;a+b 60 is the actual number of hours traveled by the hour hand, multiplied by 30° per hour, when more than 12 o'clock, the result may be greater than 360°, % represents the remainder.
d=(float)b/60*;The timing of the minute hand is 60 hours, multiplied by 360° per hour
if(c
-
Just the simplest formula, the absolute value that you can understand at a glance.
-
The program flow is fine, and the algorithm is fine.
a=30*h+;
b=6*m+;
The landlord is here to show off??
-
Didn't understand your algorithm.
Just count C out.
#include""
main()
-
Your 11 2 is the degree of each cell, then it's not 11 2, it's 6, just change (11 2)*b to 6*b.
-
Add a header file.
#include
Add to yours. #include
Topmost. It should be that the printf function is not defined, right? Just add this header file.
-
You have not considered the situation in your judgment.
For example, at 11:05, you get a negative value because you always subtract the angle of the hour hand from the angle of the minute hand. However, in the case of negative values, it is also divided into greater than 180 and less than 180. Here you don't take it into account.
After the change, the procedure is as follows:
#include""
int main(){
int a,b;
float c;
scanf("%d %d",&a,&b);
c=(b*6)-(30*a+b/2);
if (c<0) {
c=-c;if (c>180)
c=360-c;
printf("at %d:%02d the angle is %.1f degrees.",a,b,c);
elseprintf("at %d:%02d the angle is %.1f degrees.",a,b,c);
return 0;
-
I've changed it for you, you see:
#include""
int main()
int a,b;
float c;
scanf("%d %d",&a,&b);
c=(b*6)-(30*a+b/2);
Pull this sentence out separately.
if (c<0)
c=-c;Treat whether c is greater than 180 as a separate branch.
if (c>180)
c=360-c;
printf("at %d:%02d the angle is %.1f degrees.",a,b,c);
elseprintf("at %d:%02d the angle is %.1f degrees.",a,b,c);
-
#include
int main()
int a,b;
float c;
scanf("%d%d",&a,&b);
c=(b*6)-(30*a+b/2);
if(c==12)c=0;
if (c<0)
c=-c;printf("at %d:%02d the angle is %.1f degrees.",a,b,c);
else if (c>180)
c=360-c;
printf("at %d:%02d the angle is %.1f degrees.",a,b,c);
else printf("at %d:%02d the angle is %.1f degrees.",a,b,c);
I'm running like this, can you try it?
-
Your second one is else } or else if{}
-
The graphics library support option is not open.
option->linker->setting->graphics library
-
int graphdriver,graphdriver=detect;
1 Comma to reverse" ;"
2 detect, whether graphmode is defined, please check.
-
Can you describe the problem in more detail?
The second hand points to s and is 6*s degrees counterclockwise to 12 o'clock.
The minute hand points to m, which is 6*m + s 10 degrees counterclockwise to 12 o'clock, and the hour hand points to h, which is 30*h + m 2 + s 120 degrees counterclockwise to 12 o'clock, and then calculates the difference in degrees. The general idea should be this.
#include
int main() >>>More
Scope. You static char *chh;
static char *ch1;Although the address pointed to by the two pointers does not change, have you ever wondered whether the memory address they point to has been released, char chc[10]; It's local, the function is out, the lifecycle is over, and you're trying to access it with a pointer in void times(). >>>More
Use the ITOA function.
Prototype: extern char *itoa(int i); >>>More
Definition of a for loop.
for(the initial value of the variable; termination of operating conditions; The initial value of the first cycle i is 0, and it runs until i=3 stops i=2, and the condition is still satisfied, and the loop body is still executed, and the step size is 1+1 each time >>>More
Hey! This is a very simple function to write, Your Excellency is estimated to have just learned data structures, now learn sorting, lookup, it's easy to give me a reward of two hundred points, I'll help you write it right away. >>>More