BeginnersBook

  • Home
  • Java
    • Java OOPs
    • Java Collections
    • Java Examples
  • C
    • C Examples
  • C++
    • C++ Examples
  • DBMS
  • Computer Network
  • Python
    • Python Examples
  • More…
    • jQuery
    • Kotlin
    • WordPress
    • SEO
    • JSON
    • JSP
    • JSTL
    • Servlet
    • MongoDB
    • XML
    • Perl

C Program to Print Right Triangle Star Pattern

By Chaitanya Singh | Filed Under: C Programs

In this tutorial, you will learn how to write a C program to print the right triangle star pattern.

This is how a right triangle pattern looks like:

Number of rows = 6
Output: 
* 
* * 
* * * 
* * * * 
* * * * *  
* * * * * *

Program to Print Right Triangle Star Pattern

#include <stdio.h>
int main() {
  int row, column, numberOfRows=8;
  for(row=0; row<numberOfRows; row++)
  {
    for(column=0; column<=row; column++)
    {
      printf("* ");
    }
    //This is just to print the stars in new line after each row
    printf("\n");
  }
  return 0;
}

Output:
C Program to Print Right Triangle Star Pattern
Explanation of the program:

  • In this program, we are running a nested for loop. The outer for loop runs from 0 till numberOfRows, this basically prints the rows of the pattern. In this example the value of numberOfRows is 8 so the outer loop runs 8 times to print 8 rows of the right triangle star pattern.
  • The inner loop is responsible for printing the stars in the each row. It prints one star in the first row, two stars in the second row and so on.
  • After the inner loop ends there is a print statement for new line. This is to move the cursor to new line for the next row.

Practice the same program in java language here.

Related C Examples:

  • C Program to find LCM of two numbers
  • C Program to print an integer entered by the user
  • C Program to add two integers
  • C Program to generate multiplication table
❮ C TutorialC Programs ❯

Programs

  • C Programs
  • Java Programs
  • C++ Programs

Copyright © 2012 – 2022 BeginnersBook . Privacy Policy . Sitemap