Print the Right Angle Triangle Facing Left Using For Loop in C Programming


This program is written in the C programming language and is used to print a pattern of stars. The program starts by including the standard input/output library (stdio.h) and then defines a main function. Within the main function, the program declares three variables: "i", "n", and "a". The variable "a" is used to store the value entered by the user, while "i" and "n" are used as loop counters in the program.

The program then prompts the user to enter a value using the "printf" function and stores the value in the variable "a" using the "scanf" function. Next, the program uses a "for" loop with the counter variable "i" to iterate from 0 to the value of "a". Within this loop, another "for" loop is used with the counter variable "n" to iterate from 1 to (a-i).

For each iteration of the inner "for" loop, the program uses the "printf" function to print a single star. The outer loop causes the program to print one less star per row, creating a pattern of stars that decrease in number as you move down the rows. Finally, the program returns 0 to indicate that the program has completed successfully.

Source Code

#include<stdio.h>
int main()
{
  int i,n,a;
  printf("\nEnter the value:");
  scanf("%d",&a);
  for(i=0;i<=a;i++)
  {
     printf("\n");
     for(n=1;n<=(a-i);n++)
     {
       printf(" *");
     }
  }
  return 0;
}
            
To download raw file Click Here

Output

Enter the value:5
    
     
    * * * * *
    * * * *
    * * *
    * *
    *

List of Programs


Sample Programs


Switch Case in C


Conditional Operators in C


Goto Statement in C


While Loop Example Programs


Looping Statements in C

For Loop Example Programs


Array Examples in C

One Dimensional Array


Two Dimensional Array in C


String Example Programs in C


Functions Example Programs in C