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

28th Nov 2024, 3:50 AM
𝓐𝓭𝓲𝓽𝓲⚝
𝓐𝓭𝓲𝓽𝓲⚝ - avatar
2 Respostas
+ 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!"); }
28th Nov 2024, 4:47 AM
Bob_Li
Bob_Li - avatar
+ 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
28th Nov 2024, 4:20 AM
Bob_Li
Bob_Li - avatar