Pattern 34: Number pattern program in C Language
Number Pattern Program in C:
Print below number pattern program in C programming language.
The program should take number of rows as the input and display the pattern based on the user input.
Here are couple of examples with Input and output.
Example 1:
Enter how many rows you want : 5
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Example 2:
Enter how many rows you want : 9
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
6 6 6 6 6 6
7 7 7 7 7 7 7
8 8 8 8 8 8 8 8
9 9 9 9 9 9 9 9 9
Program Logic:
From above examples, We can see the pattern is printing 1 in the first row and 2 in the second row, and 3 in the third row and so on.
Which means we just need to print the rows number at each level.
But how many times we need to print for each row? We are trying to print the pattern in the triangle shape. So we can get the triangle shape by incrementing the number of values to print by 1 for each row.
So at first row, We will print 1 value, And second row we will print two times, and so on at 9th row we will print 9 times.
Let’s convert this into the c program.
Also Check:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
#include<stdio.h> int main() { int i,j,n; printf("Enter how many rows you want : "); scanf("%d",&n); for(i=1; i<=n; i++) { for(j=1; j<=i; j++) printf(" %d", i); printf("\n"); } return 0; } |
Program Output:
Similar Number Patterns:
- Come Together – The Collection of all Pattern Programs in C – SillyCodes
- Triangle Number pattern using for loops.
- Number Pattern 3.
- C Program to print below pattern
- 5 4 3 2 1
5 4 3 2
5 4 3
5 4
5 - C Program to print below pattern.
- 1
2 3
4 5 6
7 8 9 10 - C Program to print Below Pattern,
- 5
4 5
3 4 5
2 3 4 5
1 2 3 4 5 - C Program to print below pattern.
- 1
2 1
3 2 1
4 3 2 1
5 4 3 2 1 - C Program to print below pattern.
- 5
5 4
5 4 3
5 4 3 2
5 4 3 2 1
Similar Star pattern programs :
- Basic star pattern program (The square pattern with stars).
- Triangle star pattern program.
- Triangle star pattern program with Spaces.
- Pyramid star pattern.
- Reverse Pyramid program.
- Diamond Star pattern program.
- star pattern program.
- K-Star pattern program.
- Empty Rhombus program.
- X-Star pattern program
- More Star Patterns