Friday, June 6, 2008

Asterisk pattern with spaces - pattern # 1

Create a pattern with asterisk as follows :-

************
  ***********
    **********
      *********
            ******
              *****
                ****
                  ***
                    **
                      *

Solution Code :-
===========

#include <stdio.h>
int main(void)
{
int i,j,a = 1,b,c,d = 12,k,u,h = 1,x,y,z = 13,l,m,n = 6 ;

/*For spaces */

for ( b = 1 ; b <= 4 ; b++ ) { for ( c = 12 ; c >= d ; c-- )
{
printf("%c",32);
}
d = d - 1;
/* prg for stars */
for ( i = 1 ; i <= 4 ; i++) { for ( j = 12 ; j >=a ; j-- )
{
printf("%c",42);
}
break;
}
a = a + 1;
printf("\n");
}
/*Second spaces*/

for ( x = 1 ; x <= 7 ; x++ )
{
for ( y = 7 ; y <= z ; y++ )
{
printf("%c",32);
}
z = z + 1 ;

/*Second stars*/

for ( l = 1 ; l <= 6 ; l++ )
{
for ( m = 1 ; m <= n ; m++ )
{
printf("%c",42);
}
break;
}
n = n - 1 ;
printf("\n");
}
}

No comments: