Pages

Thursday, 17 September 2015

Number Pattern 16

Number pattern 16

Number Pattern 16 Coding:

#include<stdio.h>
int main()
{
 int i,j,n;
 printf("Please enter total number of lines:");
 scanf("%d",&n);
 for(i=1;i<=n;i++)
 {
      printf("\n");
  for(j=1;j<=2*(n-i);j++)
   printf(" ");
  if(i==1)
   printf("0 ");
  else
  {
   for(j=i-1;j>0;j--)
    printf("%d ",j);
   printf("0 ");
   for(j=1;j<i;j++)
    printf("%d ",j);
  }
 }
 return 0;
}

Please enter total number of lines:5

        0
      1 0 1
    2 1 0 1 2
  3 2 1 0 1 2 3
4 3 2 1 0 1 2 3 4