Pattern 29: C Program to print below triangle number pattern using loops
C Program to print number pattern 5:
Write a C program to print number pattern (5). We are going to use the two for loops to create the pattern.
The program will take the number of rows as the input and create the pattern upto the specified number of rows. Here are few sample expected outputs.
Example 1:
Example 2:
Enter how many rows you want : 7
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
Example 3:
Enter how many rows you want : 10
1
2 3
4 5 6
7 8 9 10
11 12 13 14 15
16 17 18 19 20 21
22 23 24 25 26 27 28
29 30 31 32 33 34 35 36
37 38 39 40 41 42 43 44 45
46 47 48 49 50 51 52 53 54 55
Program Explanation:
If we see the given pattern, We are basically counting the number of times we printed the a value. If you see at the first row, We printed 1. Then at second row we have 2 and 3. Which is also equal to the number of times we printed any number.
So it is basically counting the numbers. We will maintain a counter le to print the number.
Also Check:
Program to print number pattern :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
#include<stdio.h> int main() { int i,j,n; // 'count' variable to count the numbers int count=0; // Take input from the user. Num of rows to print printf("Enter how many rows you want : "); scanf("%d",&n); // Loop until we reach row value for(i=1;i<=n;i++) { for(j=1;j<=i;j++) { // At each number, Increase the value of 'count' and display count++; printf(" %d",count); } printf("\n"); } return 0; } |
Number Pattern Program Output :
Similar Number Patterns:
- Series of Number pattern programs in C.
- Basic Number Pattern program.
- 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
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