Translate

Tuesday, June 7, 2016

Write a program to print a following given pattern.

O/P


   Enter number of rows : 5
            0
          101
        21012
      3210123
    432101234
  54321012345


#include<stdio.h>
#include<conio.h>

int main()
{

 int num,r,c,sp;

 printf("Enter number of rows : ");

 scanf("%d",&num);

 for(r=0; r<=num; r++)

 {
   for(sp=num-r; sp>=0; sp--)

      {

         printf(" ");
       }

   for(c=r; c>=0; c--)

     {  
        
       printf("%d",c); 

      }

   for(c=1; c<=r; c++)

      { 

        printf("%d",c);

       }
          printf("\n");
 }

 getch();
}

No comments:

Post a Comment