Tutorial Gateway

  • C Language
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • Js

C Program to Print Inverted Right Triangle Star Pattern

by suresh

In this article we will show you, How to write a C Program to Print Inverted Right Triangle Star Pattern with example. And also show you, How to print inverted right triangle pattern with different symbols.

C Program to Print Inverted Right Triangle Star Pattern

This C program allows the user to enter the maximum number of rows he/she want to print as inverted right-angled triangle. We are going to print the inverted right triangle of * symbols until it reaches the user specified rows.

/* C Program to Print Inverted Right Triangle Star Pattern */
#include <stdio.h>
 
int main() 
{
  int Rows, i, j;
	
  printf("Please Enter the Number of Rows:  ");
  scanf("%d", &Rows);
	
  printf("\nPrinting Inverted Right Angled Triangle \n \n");
  for ( i = Rows ; i > 0 ; i-- ) 
  {
      for ( j = i ; j > 0 ; j-- ) 
      {
          printf("* ");
      }
      printf("\n");
  }
  return 0;
}

OUTPUT

C Program to Print Inverted Right Triangle Star Pattern 1

ANALYSIS
Let us see the Nested for loop

for ( i = Rows ; i > 0 ; i-- ) 
{
  for ( j = i ; j > 0 ; j-- ) 
  {
     printf("* ");
  }
  printf("\n");
}

Outer Loop – First Iteration
From the above screenshot you can observe that, The value of i is 6 and the condition (i > 0) is True. So, it will enter into second for loop

Inner Loop – First Iteration
The j value is 6 and the condition (j > 0) is True. So, it will start executing the statements inside the loop. Following statement will print * as Output

printf("* ");

Following statement will be decrement the Value of Number by 1 using the Decrement Operator

j--

This will happen until the condition inside the inner for loop fails. Next, iteration will start from beginning until both the Inner Loop and Outer loop conditions fails.

C Program to Print Inverted Right Triangle Star Pattern

This program allows the user to enter the Symbol, and number of rows he/she want to print.

/* C Program to Print Inverted Right Triangle Star Pattern */
#include <stdio.h>
 
int main() 
{
  int Rows, i, j;
  char Ch;
  
  printf("Please Enter any Symbol\n");
  scanf("%c", &Ch);
	
  printf("Please Enter the Number of Rows:  ");
  scanf("%d", &Rows);
	
  printf("\nPrinting Inverted Right Angled Triangle \n \n");
  for ( i = Rows ; i > 0 ; i-- ) 
  {
      for ( j = i ; j > 0 ; j-- ) 
      {
          printf("%c ", Ch);
      }
      printf("\n");
  }
  return 0;
}

OUTPUT

C Program to Print Inverted Right Triangle Star Pattern 2

C Program to Print Inverted Right Triangle Pattern using While Loop

In this C program we just replaced the For Loop with the While Loop. I suggest you to refer While Loop article to understand the logic.

/* C Program to Print Inverted Right Triangle Star Pattern */
#include <stdio.h>
 
int main() 
{
  int Rows, i, j;
  char Ch;
  
  printf("Please Enter any Symbol\n");
  scanf("%c", &Ch);
	
  printf("Please Enter the Number of Rows:  ");
  scanf("%d", &Rows);
	
  printf("\nPrinting Inverted Right Angled Triangle \n \n");
  i = Rows;
  while (i > 0 ) 
  {
      for ( j = i ; j > 0 ; j-- ) 
      {
          printf("%c ", Ch);
      }
      printf("\n");
      i--;
  }
  return 0;
}

OUTPUT

C Program to Print Inverted Right Triangle Star Pattern 3

Thank You for Visiting Our Blog

Placed Under: C Programming, C Programs

Trending Posts

MySQL AND Operator

Python Print Function

XML Parser Transformation in Informatica

Python index

MySQL RADIANS Function

Aggregate Transformation in SSIS Advanced Mode

C Program to find Area of a Right Angled Triangle

Python Program to find Area of a Triangle using base and height

Python Factorial

Python Rjust

  • C Programs
  • Java Programs
  • SQL FAQ’s
  • Python Programs
  • SSIS
  • Tableau
  • JavaScript

Copyright © 2019 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy