Program-7
Numbers Sequence
The program should print the numbers from 1 to n
in the format shown below. Each row should contain the same number repeated . The numbers in each row should be separated by a space.
The program compiles successfully but fails to get the desired result for some test cases due to logical errors. Your task is to fix the code so that it passes all the test cases.
Desired Output
1 1 1 1 1 1
2 2 2 2 2
3 3 3 3
4 4 4
5 5
6
Incorrect Code
void main () { int i, j, n = 6; for(i=1; i<=n; i++) { for(j=1;j<=n;j++); { printf("%d", i); } printf("\n"); } }
Correct Code
void main () { int i, j, n = 6; for(i=1; i<=n; i++) { for(j=i;j<=n;j++) { printf(" %d", i); } printf("\n"); } }
Login/Signup to comment