Write a C program to Print Number Pattern 6 with an example. For this right triangle, we are going to use For Loop and While Loop.
C program to Print Number Pattern 6 using For Loop
This program allows the user to enter the maximum number of rows he/she want to print as a right-angled triangle. Next, the compiler will print the pattern of the required number.
/* C program to Print Number Pattern 6 */
#include<stdio.h>
int main()
{
int i, j, rows;
printf(" \nPlease Enter the Number of Rows : ");
scanf("%d", &rows);
for(i = 1; i <= rows; i++)
{
for(j = i; j >= 1; j--)
{
printf(" %d", j);
}
printf("\n");
}
return 0;
}

Let us see the C Nested for loop.
Outer Loop – First Iteration
From the above C Programming screenshot, you can observe that the value of i is 7, and the condition (i <= 7) is True. So, it will enter into second for loop
Inner Loop – First Iteration
The j value is 1 and the condition (1 >= 1) is True. So, it will start executing the statements inside the loop.
printf("%d", j);
Next, we used the C Decrement Operator j– to decrement J value by 1. It will happen until the condition inside the inner for loop fails. Next, iteration will start from the beginning until both the Inner Loop and Outer loop conditions fail. For more numeric example, please refer to the Number Pattern Programs in C article.
Program to Print Number Pattern 6 using while Loop
In this C program, we just replaced the For Loop with the While Loop. I suggest you refer C Programming While Loop article to understand the logic.
/* C program to Print Number Pattern 6 */
#include<stdio.h>
int main()
{
int i, j, rows;
i = 1;
printf(" \nPlease Enter the Number of Rows : ");
scanf("%d", &rows);
while(i <= rows)
{
j = i;
while( j >= 1)
{
printf("%d", j);
j--;
}
i++;
printf("\n");
}
return 0;
}
Please Enter the Number of Rows : 9
1
21
321
4321
54321
654321
7654321
87654321
987654321
Also Read
- C Program to Print Multiplication Numbers in Right Triangle
- C Program to Print Right Triangle of Fibonacci Series Numbers Pattern