Friday, 24 July 2015

C Program - For Loop 11

C Program - For Loop 11

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n,k=1,c;
clrscr();
printf("\nEnter the number of rows :- ");
scanf("%d",&n);
for(i=0;i<=n;i++)
{
for(c=n;c>i;c--)
{
printf("  ");
}
for(j=1;j<=2*i+1;j++)
{
    if(j<i+1)
    {
printf(" %d",k);
k++;
    }
    else
    {
printf(" %d",k);
k--;
    }
}
k=1;
printf("\n");
}
getch();
}

Output :-


Enter the number of rows :- 5

              1
           1 2 1
        1 2 3 2 1
     1 2 3 4 3 2 1
  1 2 3 4 5 4 3 2 1

Back to 'C Language Programs'

No comments:

Post a Comment