pattern 25: C program to print 12345 number pattern ( Inverted triangle number pattern )
Inverted triangle number pattern Program:
Write a C Program to print the Inverted triangle number pattern using loops.
The program will take one input number from the user. Which is the number of rows for the pattern.
Here is an Example of desired pattern, When user input row size is 5.
Example:
Enter how many rows you want : 5
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
Few browsers not showing the pattern properly, Here is the pattern in Image format.
Note : This program is one of theSeries of Number pattern programs in C.
Program Logic:
We are going to use the two for loops to create the pattern. The First for or Outer for loop is used to display the row numbers. And the second for loop or Inner for loop is useful to display the column numbers.
Here is the main logic
- As it is Inverted Triangle pattern, Our outer for loop starts from the
'n' e input row size) and goes down upto the
- At each iteration of outer loop, The inner loop goes from 1 to 'i' ( Here 'i' outer loop iterator).
- So as we are stopping the iteration at 'i' e are creating the Triangle shape.
Inverted triangle number pattern Program :
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> int main() { int i,j,n; // Enter the number of rows for your pattern printf("Enter how many rows you want : "); scanf("%d",&n); // As it is Inverted Pattern, We are going to start from the end // i.e the loop start from the 'n' and comes down to 0 for(i=n;i>0;i--) { // We will print the number only if the j<=i for(j=1;j<=i;j++) printf(" %d",j); printf("\n"); } return 0; } |
Program Output:
We used GNU GCC compiler to compile and run the program.
Similar Number Patterns:
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
int main()
{
int i,j,k,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;
}
Read more: http://www.sillycodes.com/2015/11/write-c-program-to-print-below-number-using-loops.html
int main()
{
int i,j,k,n;
printf("Enter how many rows you want : ");
scanf("%d",&n);
for(i=n;i>0;i–)
{
for(j=i;j<=n;j++)
printf(" %d",j);
printf("n");
}
return 0;
}
Read more: http://www.sillycodes.com/2015/11/pattern-31-c-program-to-print-below.html
#include
int main()
{
int i,j,k,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",j);
printf("n");
}
return 0;
}
Read more: http://www.sillycodes.com/2015/10/pattern-24-c-program-to-print-triangle-number-pattern.html
Pattern 7
Write a program to print the given pattern.
Input Format:
Input consists of a single integer.
Output Format:
Refer sample output. There is a trailing space at the end of each line.
Sample Input:
5
Sample Output:
1
2 2
3 3 3
4 4 4 4
5 5 5 5 5
Pattern 6
Write a program to print the given pattern.
Input Format:
Input consists of a single integer.
Output Format:
Refer sample output. There is a trailing space at the end of each line.
Sample Input:
5
Sample Output:
5
4 5
3 4 5
2 3 4 5
1 2 3 4 5
Write a program to print the given pattern.
Input Format:
Input consists of a single integer.
Output Format:
Refer sample outputs. There is a trailing space at the end of each line.
Sample Input:
5
Sample Output:
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5