In this tutorial, we will learn how to print odd number patterns in C. Before that, you may go through the following topic in C.
The program takes a user input for the number of rows and prints the number pattern of the pyramid for odd numbers in C.
C Program to print Odd Number Pattern
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <stdio.h> void main() { int i, j, k = 1, rows; printf("Enter the no. of rows: "); scanf("%d", &rows); for (i = 1; i <= rows; i++) { for (j = 1; j <= i; j++) { printf("%2d ", k); k = k + 2; } printf("\n"); } getch(); } |
Output: