Write a C Program to print pyramid ?
Hello friends, we are back with another simple and most interesting C Program.In our last blog we saw you how to write c program to check whether the number is palindrome or not.In this program we will make a pyramid with the help of C programming Language.This kind of problems is useful for beginners to understands the fundamentals of loops and spaces.
A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence. Some of these patterns are triangles which have special importance in mathematics.Let’s see the programming part of this program.
C Programming Code to print pyramid:
int pyramid(int row )
for ( i=1;i<=row;i++)
return ( row );
printf(“enter the number of lines”);
pyramid ( line );
Logic behind this program:
We first take the number of rows in the pattern as input from user using scanf function.
One iteration of outer for loop will print a row of pyramid.
Inner for loop prints the initial spaces for every line and nested while loop prints (2*r – 1) space separated stars for rth row of pyramid.
Stay connected with us for more C Programming Language.Leave a comment for any question.