ad

Thursday, April 10, 2025

C Program To Print Rhombus Star Pattern

                                      C Program

C Program To Print Rhombus  Star Pattern

Example 


#include <stdio.h>

int main()
{
    int i, j, rows;

 
    printf("Enter rows: ");
    scanf("%d", &rows);

    for(i=1; i<=rows; i++)
    {
   
        for(j=1; j<=rows - i; j++)
        {
            printf(" ");
        }

       
        for(j=1; j<=rows; j++)
        {
            printf("*");
        }

       
        printf("\n");
    }

    return 0;
}

C Program To Print Rhombus  Star Pattern

Explain Program

Step :1

#include <stdio.h>

  input/output library to printf() and scanf().

 Step :2

int main()

every C program. Execution starts  

Step :3

int i, j, rows;

Variable declarations:

 i: Loop variable for rows.

 j: Loop variable for spaces and stars.

rows: Number of rows for the rhombus

Step :4

printf("Enter rows: ");

scanf("%d", &rows);

user to input an integer (rows)

 The height of the rhombus.

Step :5

for(i = 1; i <= rows; i++)

Outer loop control the number of rows to be printed.

It runs from 1 to rows.

 iteration prints one row of the rhombus.

Step :6

for(j = 1; j <= rows - i; j++)

{

    printf(" ");

}

This inner loop prints spaces before the stars on each line.

 The number of spaces decreases as i increase

 For row 1: rows - 1 space

 For row 2: rows - 2 space

 Step :7

for(j = 1; j <= rows; j++)

{

    printf("*");

}

 loop prints a fixed number of stars: exactly rows stars on each line.

 Step :8

printf("\n");

 next line after printing . 

Program Exit:

return 0;

C Program To Print Rhombus  Star Pattern

 Program Output :- 

C Program To Print Rhombus  Star Pattern




No comments:

Post a Comment