C language clock angle problem, C language calculation clock angle problem

Updated on technology 2024-03-18
14 answers
  1. Anonymous users2024-02-06

    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;

  2. Anonymous users2024-02-05

    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

  3. Anonymous users2024-02-04

    Just the simplest formula, the absolute value that you can understand at a glance.

  4. Anonymous users2024-02-03

    The program flow is fine, and the algorithm is fine.

    a=30*h+;

    b=6*m+;

    The landlord is here to show off??

  5. Anonymous users2024-02-02

    Didn't understand your algorithm.

    Just count C out.

    #include""

    main()

  6. Anonymous users2024-02-01

    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.

  7. Anonymous users2024-01-31

    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.

  8. Anonymous users2024-01-30

    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;

  9. Anonymous users2024-01-29

    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);

  10. Anonymous users2024-01-28

    #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?

  11. Anonymous users2024-01-27

    Your second one is else } or else if{}

  12. Anonymous users2024-01-26

    The graphics library support option is not open.

    option->linker->setting->graphics library

  13. Anonymous users2024-01-25

    int graphdriver,graphdriver=detect;

    1 Comma to reverse" ;"

    2 detect, whether graphmode is defined, please check.

  14. Anonymous users2024-01-24

    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.

Related questions
9 answers2024-03-18

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

6 answers2024-03-18

Use the ITOA function.

Prototype: extern char *itoa(int i); >>>More

16 answers2024-03-18

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

9 answers2024-03-18

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