C Program to Print Downward Triangle Star Pattern

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

C Program to Print Downward Triangle Star Pattern using while loop

In this Downward Triangle Star Pattern program, we replaced the for loop with the 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 do while loop and prints the Downward Triangle Stars pattern.

#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.

#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
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ @ 
@ @ @ @ @ @ @ 
@ @ @ @ @ @ 
@ @ @ @ @ 
@ @ @ @ 
@ @ @ 
@ @ 
@