Write a C program for the following pyramid * * * * * *


  • * * * * * *
  • * * * * *
  • * * * *
  • * * *
  • * *
  • *
  • * *
  • * * *
  • * * * *
  • * * * * *
  • * * * * * *

Asked by:- BTBLProduction
0
: 531 At:- 7/16/2023 2:15:10 AM
Pyramid * Coding







1 Answers
profileImage Answered by:- vikas_jk

You can break this into 2 parts, first inverted triangle and then left hand side triangle, so C Code for it will look like below

#include <stdio.h>
int main()
{
    //declare variables to use
    int i, j, rows;
    
    //now loop for each row
    for(i=1; i<=5; ++i)
    {
        //this loop will print * until value of outer loop variable(i) is greater than 
        //inner loop vairable(j)
        for(j=5; j>=i; j--)
        {
            printf("*");
        }
        //as soon as inner loop(j) value becomes greater than outer loop printing * ends
       // & it prints new line using \n
        printf("\n");
    }

    //now loop for each row
    for(i=2; i<=5; ++i)
    {
        //this loop will print * until value of outer loop variable(i) is greater than 
        //inner loop vairable(j)
        for(j=1; j<=i; ++j)
        {
            printf("*");
        }
        //as soon as inner loop(j) value becomes greater than outer loop printing * ends
       // & it prints new line using \n
        printf("\n");
    }
    return 0;
}

Output:

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

Sample https://onlinegdb.com/ZuFVWV4v0

For more Star program in C (Pyramid pattern program examples) check link.

0
At:- 7/17/2023 8:43:10 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use

Subscribe Now

Subscribe to our weekly Newsletter & Keep getting latest article/questions in your inbox weekly