Write a C program to print the Downward Triangle Star Pattern using the while loop, for loop, and functions with an example. The below Downward program uses the nested for loop to iterate the rows and print the pattern of stars.
#include<stdio.h>
int main(void)
{
int rows;
printf("Enter Rows to Print Downward Triangle = ");
scanf("%d", &rows);
for (int i = rows - 1; i >= 0; i-- )
{
for (int j = 0 ; j <= i; j++ )
{
printf("* ");
}
printf("\n");
}
}

C Program to Print Downward Triangle Star Pattern using while loop
In this Downward Triangle Star Pattern program, we replaced the the C language for loop with the C programming while loop.
#include<stdio.h>
int main(void)
{
int rows;
printf("Enter Rows to Print Downward Triangle = ");
scanf("%d", &rows);
int i = rows - 1;
while ( i >= 0 )
{
int j = 0 ;
while ( j <= i )
{
printf("* ");
j++;
}
printf("\n");
i--;
}
}
Output
Enter Rows to Print Downward Triangle = 9
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
This example uses the C do while loop and prints the Downward Triangle Stars pattern. For more star pattern examples, please refer to the C Star Pattern Programs article.
#include<stdio.h>
int main(void)
{
int rows;
printf("Enter Rows to Print Downward Triangle = ");
scanf("%d", &rows);
int i = rows - 1;
do
{
int j = 0 ;
do
{
printf("* ");
j++;
} while ( j <= i );
printf("\n");
i--;
} while ( i >= 0 );
}
Output
Enter Rows to Print Downward Triangle = 14
* * * * * * * * * * * * * *
* * * * * * * * * * * * *
* * * * * * * * * * * *
* * * * * * * * * * *
* * * * * * * * * *
* * * * * * * * *
* * * * * * * *
* * * * * * *
* * * * * *
* * * * *
* * * *
* * *
* *
*
In the below Downward Triangle pattern of stars program, the user-defined function accepts the rows and characters to print the pattern using the symbol. Refer to the C programs article.
#include<stdio.h>
void loopLogic(int rows, char ch)
{
for (int i = rows - 1; i >= 0; i-- )
{
for (int j = 0 ; j <= i; j++ )
{
printf("%c ", ch);
}
printf("\n");
}
}
int main(void)
{
int rows;
char ch;
printf("Enter Character = ");
scanf("%c", &ch);
printf("Enter Rows to Print Downward Triangle = ");
scanf("%d", &rows);
loopLogic(rows, ch);
}
Output
Enter Character = @
Enter Rows to Print Downward Triangle = 16
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @ @
@ @ @ @ @ @ @ @
@ @ @ @ @ @ @
@ @ @ @ @ @
@ @ @ @ @
@ @ @ @
@ @ @
@ @
@
Also Read
- C Program to Print Right Pascal Triangle Star Pattern
- C Program to Print Left Pascal Triangle Star Pattern