Tuesday , January 23 2018
Home / C / c program for pattern#15

c program for pattern#15


This is a simple pyramid pattern which can be implemented using nested loop – either while or for loop.

int main()
int n,i,j,p; // initialize the variables
printf("Enter the number of lines in the pattern\n");
scanf("%d",&n);   // number of lines to be printed
for(i=1;i<=n;i++)  // loop for spaces in 1st triangle
for(j=1;j<=n-i;j++)   // loop for 1st part in the triangle
printf(" ");
p=1;            //   initialize a variable p to 1.
for(j=1;j<=i;j++)   //loop for 1st part  of the triangle
printf("%d",p++);  // printing the value of p first and then increment the pointer
for(j=1;j<i;j++)  //loop for 2nd part of triangle
printf("%d",p++);   // printing the value of p and increment the pointer but at one less value
printf("\n");  // next line
return 1;


Also See:   C program to remove extra lines or blank lines from a file

c program for pattern #15

Check Also

How to Solve Linear Equation in One Variable In C Programming?

C Program to Solve any Linear Equation in One Variable Find complete C program to ...

Leave a Reply

Your email address will not be published. Required fields are marked *