C Language "Rhombus number pattern using for loop" program with output
#include <stdio.h>
int main() { int n, i, j, space; printf("Enter the number of rows: "); scanf("%d", &n); for (i = 1; i <= n; i++) { for (space = 1; space <= n - i; space++) { printf(" "); } for (j = 1; j <= 2 * i - 1; j++) { printf("%d ", j); } printf("\n"); } for (i = n - 1; i >= 1; i--) { for (space = 1; space <= n - i; space++) { printf(" "); } for (j = 1; j <= 2 * i - 1; j++) { printf("%d ", j); } printf("\n"); } return 0; }Output
Enter the number of rows: 5
1
1 2 3
1 2 3 4 5
1 2 3 4 5 6 7
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7
1 2 3 4 5
1 2 3
1
Comments
Post a Comment