Wednesday 22 August 2012

Loop control structure061

Write a program to construct  the image shown below.
                 
                  1 2 3 4 5 6 7 8 9 8 7 6 5 4 3 2 1
                  1 2 3 4 5 6 7 8    8 7 6 5 4 3 2 1
                  1 2 3 4 5 6 7          7 6 5 4 3 2 1
                  1 2 3 4 5 6                6 5 4 3 2 1
                  1 2 3 4 5                      5 4 3 2 1
                  1 2 3 4                            4 3 2 1
                  1 2 3                                  3 2 1
                  1 2                                        2 1
                  1                                              1     



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

void main ( )
{
           int         i, j, s = - 1, k;
           clrscr ( );
                                           
           printf ("\n\t\t\t\t Design of Numbers");
           printf ("\n\n\n\t\t\t");
                                           
           for ( i = 9; i >= 1; i-- )
           {                                 
                           for ( j = 1; j <= i; j++ )
                           {                                   
                                           printf("%d ", j);
                           }                                      
                           for ( k = 1; k <= s; k++)
                           {                                     
                                           printf ("  ");
                           }                                             
                           if ( i == 9 )
                                    j = i - 1;
                           else                        
                                    j = i;
                           for ( ; j >= 1; j-- )
                           {                             
                                            printf ("%d ", j);
                           }                                        
                           s = s + 2;
                           printf ( "\n\t\t\t" );
           }
           getch();
}



Click here to contact us






No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...