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




C Program to Display Floyd’s Triangle Pyramid Pattern

C Program to Display Floyd’s Triangle Pyramid Pattern

Example 


#include<stdio.h>
int main()
{

int row,i,j,number=1;
clrscr();
printf("enter the number");
scanf("%D",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",number);
++number;
}
printf("\n");
}
getch();
return 0;
}

C Program to Display Floyd’s Triangle Pyramid Pattern

Explain Program

Step :1

#include <stdio.h>

  • Standards Input/Output Library.
  •  using printf() and scanf().

Step :2

int main()

  •  entry point of the program.

Step :3

int row, i, j, number = 1;

Declares variables:-
  • row :- User input for number of rows in Floyd's Triangle.
  • i :- Loop variable for rows.
  • j :- Loop variable for elements in each row.
  • number :- Holds the current number to print; starts at 1.

Step :4

printf("Enter the number of row ");

  •  input how many rows they want in the triangle.

Step :5

scanf("%d", &row);

  •  user input and stores  variable row.
  • format specifier for integers.

Step :6

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

  •  number of rows in the triangle.
  • Runs from 1 to row 

Step :7

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

  • Control  the number of element  row.
  • Each row i contains exactly i numbers.

Step :8

printf("%d ", number);

  • Prints a space.

Step :9

printf("\n");

  • next line after each row is printed

Step :10

return 0;

successful termination of the program

C Program To Print Floyd's Triangle Pyramids  Pattern

 Program Output :- 

c program print floyd program


Related Post :-

c program to print full pyramid star

c program to print pascals triangle

c program to print inverted half

Saturday, March 22, 2025

C Program to Display Pascal’s Triangle Using Loops

C Program

C Program to Display Pascal’s Triangle Using Loops

Example 


#include<stdio.h>

int main()

{

    int  row,coef=1,space,i,j;

    printf("enter the number");

    scanf("%d",&row);

    for (i=0;i<row;i++)

    {
    for(space=1;space<=row -i;space++)

    printf(" ");

    for(j=0;j<=i;j++)

    {

    if(j==0||i==0)

    coef =1;

    else

    coef=coef * (i-j+1)/j;

printf("%4d",coef);

    }

    printf("\n");

    }

return 0;

}


C Program to Display Pascal’s Triangle Using Loops

Explain Program

Step :1

#include <stdio.h>

  •  standard input/output library for printf() and scanf() function

Step :2

int main()

  • Starting point of the program.

Step :3

Variable Declarations

int row, coef = 1, space, i, j;

  • row: Number of rows to print (user input).
  • coef: Coefficient in Pascal’s Triangle, initialized to 1. It holds the binomial coefficient.
  • space: Used to align the triangle by printing leading spaces.
  • i: Outer loop counter (represents the current row).
  • j: Inner loop counter (represents the position in the row).

Step :4

Input Prompt

printf("enter the number");

scanf("%d", &row);

  •  rows of Pascal's Triangle they want to display

Step :5

Outer Loop: Iterates through rows

for (i = 0; i < row; i++)

  • i  from 0 to row - 1 (0-based index).
  • Each iteration corresponds to one row of Pascal’s Triangle.

Step :6

Printing Leading Spaces

for (space = 1; space <= row - i; space++)

    printf(" ");

  • Aligns the triangle by printing spaces before numbers.
  • As i increases, fewer spaces are printed.

Makes the triangle centered

Step :7

Inner Loop: Calculates and Prints Coefficients

for (j = 0; j <= i; j++)

  • Print  value  the current row (row i has i+1 value).

Step :8

if (j == 0 || i == 0)

    coef = 1;

else

    coef = coef * (i - j + 1) / j;

  • This is an efficient iterative formula to calculate binomial coefficients without using factorials:

Step :9

printf("%4d", coef);

  • %4d ensures that each number takes at least 4 spaces, which helps align the triangle neatly.

Step :10

printf("\n");

  •  starts the next one.
return 0


C Program to Display Pascal’s Triangle Using Loops

 Program Output :- 



Related Post :-


C program number pattern

Friday, March 21, 2025

C Program to Print Full Pyramid of star pattern

C Program 

https://webdesigningtheory.blogspot.com/2025/06/c-program-to-print-alphabet-t-star.html

C Program  to Print Full Pyramid of star pattern

Example 


#include<stdio.h>
void main ()
{
int i,space,r,k=0;
   
printf("enter the number");
scanf("%d",&r);
for(i=1;i<=r;i++,k=0)
{
for(space=1;space<=r-i;space++)
{
printf(" ");
}
while(k !=2*i-1){
printf("*");
++k;
}
printf("\n");
}
return 0;
}


C Program  to Print Full Pyramid of star pattern

Explain Program

Step :1

#include <stdio.h>

  • Standard Input Output header file.
  • using printf() and scanf() functions.

Step :2

void main()

  • The program execution starts 

Step :3

Variable Declarations

int i, space, r, k = 0;

  • i: loop counter for rows.
  • space: counter for printing leading spaces in each row.
  • r: number of rows in the pyramid (user input).
k: used to control the number of asterisks (*) printed in each row

Step :4

printf("enter the number");

scanf("%d", &r);

  •  enter how many rows they want in the pyramid.

Step :5

for(i = 1; i <= r; i++, k = 0)

  • Runs from i = 1 to r
  •  iteration correspond to one row of the pyramid.
  • k = 0 resets the asterisk counter for each row.

Step :6

Inner Loop 1: Printing Leading Spaces

for(space = 1; space <= r - i; space++)

{

    printf(" ");

}

  • This prints leading spaces before the stars in each row.
  •  row number (i) increases, the number of spaces decreases.
  • centers the pyramid.

Step :7

. Inner Loop 2: Printing Stars

while(k != 2 * i - 1)

{

    printf("*");

    ++k;

}

  •  print the asterisks (*) in each row.
  •  number of stars increases by 2 with each row.
  • The formula 2 * i - 1 gives an odd number of stars (1, 3, 5, ...), forming a full pyramid.

Step :8

printf("\n");

  • After printing spaces and stars for a row, it moves the cursor to the next line.

Step :9

return 0;

C Program  to Print Full Pyramid of star pattern

 Program Output :- 

C Program  to Print Full Pyramid of star pattern




Related Post :-

free online learn C programming-course

C Program print Inverted Right Half Pyramid Star Pattern

Thursday, March 20, 2025

C Program to Print Inverted half Pyramid of Number

https://webdesigningtheory.blogspot.com/2025/03/c-program-to-print-pascals-triangle.html

C Program to Print Inverted half Pyramid  of Number

Example 


#include<stdio.h>
void main ()
{
int i,j,r;

printf("enter the number");
scanf("%d",&r);
for(i=r;i>=1;i--)
{
for(  j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}

C Program to Print Inverted half Pyramid  of Number

Explain Program

Step :1

#include <stdio.h>

 standard input/output library.

Step :2

void main()

 main function where the program starts.

Step :3

Variable Declarations

int i, j, r;

r: The number of rows (user input).

i: Controls the outer loop (rows).

 j: Controls the inner loop (columns/numbers per row).

Step :4

printf("enter the number");

scanf("%d", &r);

 user to enter an integer value r

 the number of rows in the pattern

Step :5

Outer Loop (Row Control)

for(i = r;  i >= 1;  i--)

Start  from i = r and decrements down to 1.

Each iteration represent one row in the output.

 number of values printed in a row equals i.

Step :6

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

{

    printf("%d", j);

}

each row, this loop prints numbers starting from 1 up to i.

Step :7

printf("\n");

row move the cursor to the next line.

Step :8

return 0;

C Program to Print Inverted half Pyramid  of Number

 Program Output :- 


C Program to Print Inverted half Pyramids  of Number


Related Post :-

C Program Print Right Half Character Pyramid Pattern

C program print square star pattern