Write a C program to construct a pyramid of numbers
.
Algorithm:
Step 1: Start Step 2: Read n value as integer Step 3: for p:1 to n increment p by 1 begin for q:1 to n increment q by 1 m = p; for q:1 to p increment q by 1 print m++ m = m  2; for q:1 to p increment q by 1 print m end Step 4: Stop
Program:
#include <stdio.h> #include <conio.h> #include <math.h> void main() { int i, n, j, p = 40; clrscr(); printf("enter the number of lines\n"); scanf("%d", &n); printf("pyramid shape is\n"); for(i = 0; i <n ; i++) { gotoxy(p, i + 1); for(j = 0  i; j <= i; j++) { printf("%3d", abs(j % 2)); } p = p  3; printf("\n"); } getch(); }
Input & Output:
enter the number of lines
5
pyramid shape is
0
1 0 1
0 1 0 1 0
1 0 1 0 1 0 1

CreatedOct 11, 2014

UpdatedDec 25, 2014

Views13,348
You May Like
Write a C program to count the lines, words and characters in a given text.
Write a C program to find the roots of a quadratic equation
.
Write a C program to find the sum of individual digits of a positive integer.
Write a C program to generate all the prime numbers
between 1 and n, where n is a value supplied by the user.
Write a C program, which takes two integer operands and one operator from the user, performs the operation and then prints the result. (Consider the operators +,,*, /, % and use switch statement
)
Write C programs that use both recursive
and nonrecursive functions
 To find the
factorial
of a given integer.  To find the
GCD
(greatest common divisor) of two given integers.