Pattern 31: C Program to print below number pattern using for loops
Program to print below Number Pattern :
Write a C Program to print the below Number pattern which looks like a triangle number pattern. The program should take the input from the user, The input number is going to be the number of rows which we are going to print in our pattern.
Before going to write the program, Let’s see how exactly pattern looks like for different input row values.
Example 1:
Enter how many rows you want : 5
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
Example 2:
Enter how many rows you want : 10
10
9 10
8 9 10
7 8 9 10
6 7 8 9 10
5 6 7 8 9 10
4 5 6 7 8 9 10
3 4 5 6 7 8 9 10
2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
Program Logic:
So if we observe above example patterns, We can see the pattern starts from the 'n' ( i.e row value)
At top row the pattern only have one value and then at second row it has two values, so on. and at the last row we have 'n' mber of values.
So we need two for loops. The outer for loop and Inner for loop.
- The Outer or First for loop ('i') starts from the 'n' and goes down to 1
- The Inner for loop will always starts with 'i' (which is the outer loop iterator) and At each iteration of outer for loop, The inner for loop will going to print the number value from 'i' to 'n'.
📢 This program is one of the Series of Number pattern programs in C.
Number Pattern Program :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
#include<stdio.h> int main() { int i,j,n; // Take the row value from the user printf("Enter how many rows you want : "); scanf("%d",&n); // The pattern start from the 'n' and goes down to 1 // So our loop will also starts from 'n' for(i=n;i>0;i--) { for(j=i;j<=n;j++) printf(" %d",j); printf("\n"); } return 0; } |
Program Output :
Similar Number Patterns:
- 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 - C Program to print below pattern.
-
12 34 5 67 8 9 10
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