Write a C program to print following pyramid!!!

 TASK-

Write a C program to print following pyramid!!!



Note : We are not going to specify the size of pattern!!!

CODE:




#include<stdio.h>
int main(){
int n,i,j,o=1;
printf("Enter number of rows of upper triangle: ");
scanf("%d",&n); 
/* We are getting number of rows for upper triangle only because lower triangle uses the properties of upper one!!!*/
printf("\n");
for (i=1;i<=n;i++)
{ 
//algorithm for space!!! in upper triangle space is decreasing as rows are increasing
	for (int s=n-i;s>0;s--)
	printf(" ");
	for (j=0;j<o;j++)
	{
		printf("*");
	}
 printf("\n");
 o=o+2; //number of starts is increasing in odd numbers
}
o=o-2;
for (i=1;i<=(n-1);i++)
{
	o=o-2;
	//algorithm for space!!! in lower triangle space is increasing as rows are increasing
	for (int s=0;s<i;s++)
	printf(" ");
	for (j=0;j<o;j++)
	printf("*");
	printf("\n");
}
getchar();
return 0;

As Already stated --> we are not specifying the size hence see the Expected output!!

For more pyramid programs --> Pyramid

EXPECTED OUTPUT:

NEED WORK PRODUCE WORK

My name is Abdul Rehman I am from Pakistan. I am doing BS in Computer and information sciences. Currently, I am creating these blogs to help students of computer sciences all over the world..

1 Comments

Post a Comment
Previous Post Next Post