Pattern 26 : C Program to print Triangle number pattern 2 using for loops
Triangle Number Pattern 2 :
Write a C program to print below Triangle Number pattern (II).
Example:
Enter how many rows you want : 5
1 2 3 4 5
2 3 4 5
3 4 5
4 5
5
Note, That at each row, The Number at the start is removed. So If at first row i have value 1 then at row two my 1 will be removed and 2 will replace it.
Note : This program is one of the Pattern Programs in C
Triangle Number Pattern 2 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; // Take the input from the user printf("Enter how many rows you want : "); scanf("%d",&n); // As it is Inverted Trianlge, The loop starts from the 'n' // and reduces till we reach the 0. for(i=n;i>0;i--) { for(j=(n-i)+1; j<=n; j++) printf(" %d",j); printf("\n"); } return 0; } |
Triangle Pattern Program Output:
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
code for above program.
#include
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=n;j>=i;j–)
printf(" %d",i);
printf("n");
}
return 0;
}
Here is the link for above program,
http://www.sillycodes.com/2015/11/pattern-28-c-program-to-print-number.html
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 4
3 3 3
2 2 2 2
1 1 1 1 1
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:
5 4 3 2 1
5 4 3 2
5 4 3
5 4
5