Wave Pattern
C
Hard
9 views
Problem Description
* * *
* * * *
* *
* * * *
* * *
Sine wave simulation. Condition based on rows and columns: (i+j)%4 == 0 and (i+j)%4 == 2
Official Solution
#include <stdio.h>
int main() {
int rows = 5, cols = 9;
int i, j;
for (i = 0; i < rows; i++) {
for (j = 0; j < cols; j++) {
if ((i + j) % 4 == 0 || (i + j) % 4 == 2)
printf("*");
else
printf(" ");
}
printf("n");
}
return 0;
}
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!