ad

Friday, March 14, 2025

Write C Program to Print Right Half Character Pyramid Pattern

https://webdesigningtheory.blogspot.com

 Write C Program to Print Half Character Pyramid  Pattern 

Example 


#include<stdio.h>
int main ()

{

int i,j,n;
 printf("enter the no of line");
 
scanf("%d",&n);
 
for(i=1;i<=n;i++)
  {
 
for(j=1;j<=i;j++)
  {
 
printf("%c",(char)(i+64));
  }
 
printf("\n");
  }
   
getch();  

}


Write C Program to Print  Right Half Character Pyramid  Pattern 

Explain Program

Step :1

#include<stdio.h>

  • standard input/output library.
  •  use printf() and scanf() functions.

Step :2

int main()

  • use starting point of your program.

Step :3

. int i, j, n;

  • i – controls the row number
  • j – controls to the numbers of characters printed per row
  • n – stores the number of lines entered by the user

Step :4

printf("enter the no of line");

  •  user to enter the number of lines to print.

Step :5

scanf("%d", &n);

  • number of lines (rows) from the user and stores it in variable n.

Step :6

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

  • Outer loop: runs from 1 to n
  • Each iteration represents one row of the pattern.

Step :7

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

  • Inner loop: runs from 1 to i
  • It controls how many times a character is printed on each row.

Step :8

printf("%c", (char)(i + 64));

      This is the most interesting part!

  •  printing a character, not a number.

Step :9

 printf("\n");

  • After printing one row, move to the next line

 getch();

Write C Program to Print  Right Half Character Pyramid  Pattern  

 Program Output :

Write C Program to Print  Right Half Character Pyramid  Pattern

Related Post :-

No comments:

Post a Comment