Home>

I'm in trouble because I don't understand the problem with paiza.

"I thought it was boring because a normal cuckoo clock only sounds once an hour. You modified the cuckoo clock to make a super cuckoo clock. This super cuckoo clock is x hours y minutes when the time is x hours y minutes x + Y sounds "FIZZ" when it is a multiple of 3, "BUZZ" when it is a multiple of 5, and "FIZZBUZZ" when it is a multiple of 3 and a multiple of 5, and it does not sound if none of these are true. Note that 0 is a multiple of 3 and a multiple of 5. Please output the state of the super cuckoo clock for each minute from 00:00 to 23:59.

Expected output
Cuckoo clock barks at 0:00
Cuckoo clock barks at 0:01
...
Cuckoo clock barks at 23:58
Cuckoo clock barks at 23:59

Output the cuckoo clock bark for each minute from 00:00 to 23:59 in the above format.
Output only line breaks when nothing sounds. "

If this is left as it is, line breaks will occur at all times when you do not cry, so line breaks only once and then "FIZZ"
I want to change the specifications to output such as.

What I tried
#include<stdio.h>
int main (void) {
    int num;
    for (int x = 0;x<= 23;x ++) {
        for (int y = 0;y<61;y ++) {
            num = x + y;
            if (num == 0 || (num% 15 == 0)) {
                printf ("FIZZBUZZ");
            } else if (num% 3 == 0) {
                printf ("FIZZ");
            } else if (num% 5 == 0) {
                printf ("BUZZ");
            } else {printf ("\ n");}
        }
    }
    return 0;
}
  • Answer # 1

    C operator precedence
    Surplus%%Is an addition+It has a higher priority than.
    x + yIf you want to find the remainder for(x + y)% Number to dividePlease.


    If this is left as it is, line breaks will occur at all times when you do not cry, so I would like to change the specification so that line breaks occur only once and the next "FIZZ" etc. is output.

    Why don't you prepare a flag that has already broken a line and clear the flag when it sounds?

  • Answer # 2

    The number of for statement repetitions was incorrect.
    The final code looks like this:

    #include<stdio.h>
    int main (void) {
        int num;
        for (int x = 0;x<= 23;x ++) {
            for (int y = 0;y<60;y ++) {
                num = x + y;
                if (num == 0 || (num% 15 == 0)) {
                    printf ("FIZZBUZZ \ n");
                } else if (num% 3 == 0) {
                    printf ("FIZZ \ n");
                } else if (num% 5 == 0) {
                    printf ("BUZZ \ n");
                } else {
                    printf ("\ n");
                }
            }
        }
    }