C

C Program To Print Inverted Triangle Star Pattern

In this tutorial, we are going to see how to write a C program to print inverted or reverse triangle star patterns. To print a pyramid or an inverted triangle of N lines made of stars, We use for loop. Below is the logic for displaying a pyramid or an inverted triangle of N lines made of stars in C programming.
 

Input :
Number of Lines: 5

Output :
* * * * * * * * *
  * * * * * * *
    * * * * *
      * * *
        * 

 

 

C Program To Print Inverted Triangle Star Pattern
#include <stdio.h>

int main()
{
  int i, j, lines, s=0;

  printf("Enter the number of lines: ");
  scanf("%d",&lines); 
  printf("\n");
  
  for(i=lines; i>=1; i--)
  {
    for(j=1; j<=s; j++) 
      printf(" ");
    
    for(j=1; j<=i; j++) 
      printf("*");
    
    for(j=i-1; j>=1; j--)
      printf("*");
    
    printf("\n");
    s++;
  }
  
  return 0;
}

Output:

Entrez le nombre de lignes: 5

*********
 *******
  *****
   ***
    *

 

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *