C program to create a pyramid - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Thursday, December 19, 2019

C program to create a pyramid - My CS Tutorial

C program to create a pyramid pattern by alphabets.
In this tutorial we will learn how to write a program that print or create a pyramid by alphabets.We will create a pyramid whose upper end will be on the right.
This pyramid is create by alphabets(upper and lower case letter) and symbols.In the first we will enter the range of rows for pyramid and then print the pyramid. Which number are enter throw the keyboard for rows' value those numbers' rows are available in that pyramid(triangle).


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
    int a,b,alpha,rows,temp;
    printf("\n Enter the range of rows:\n ");
    scanf("%d",&rows);
    printf("\n");
    for(a=1;a<=rows;a++)
    {

     alpha=64+rows;
        for(b=1;b<=a;b++)
        {
            printf("%c ",alpha);
            alpha--;
        }
        printf("\n");
    }

 for(a=rows-1;a>=1;a--)
 {
  alpha=64+rows;
  for(b=a;b>=1;b--)
  {
   printf("%c ",alpha);
    alpha--;
  }

  printf("\n");
 }
 getch();
}


OUTPUT:




In this output we can see that the range or size of pyramid is 18 and the total lines of alphabets is 18.
we will enter the range(size) of this pyramid and press the enter button then the pyramid will be print on to the screen.This pyramid is a triangle also.This is a pyramid whose upper end will be on the right.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.If you have any method of this program or want to give any suggestion send email on hc78326@gmail.com

Created by-- HARSH CHAUHAN

No comments:

Post a Comment