0
Doubt in C
#include <stdio.h> int main() { int a, b, c; for(c = 1; c < 9; c++){ printf("\n"); if (c % 2 == 0){ for(b = 0; b < 4; b++){ printf("⬜️⬛️"); } } else{ for(a = 0; a < 4; a++){ printf("⬛️⬜️"); } } } printf("\n Lets Play!"); return 0; } . . . Ques: if(c%2==0); What does this line mean? Why c% ?
2 Respuestas
+ 2
it can be simpler:
#include <stdio.h>
int main() {
for(int i=1; i<9; i++){
if(i%2==0)
puts("⬜️⬛️⬜⬛⬜⬛⬜⬛");
else
puts("⬛️⬜️⬛⬜⬛⬜⬛⬜");
}
puts(" Lets Play!");
}
+ 1
c%2==0 is a way to check if c is even. c=0, 2,4,6,8
This is so that we can alternate between printing
⬜⬛⬜⬛⬜⬛⬜⬛ if(c%2==0)
and
⬛⬜⬛⬜⬛⬜⬛⬜ (else)
to print the checkerboard pattern