Create a Diamond out of asterisk whose value is 42 in Ascii code as below :-
*
***
*****
*******
*********
*******
*****
***
*
Solution Code :-
===========
#include <stdio.h>
int main(void)
{
int space ,list = 1,i,f,q,push = 9,a,b,c = 4,m,n,o = 1;
/*for creating upper space*/
for ( space = 1; space <= 5; space++ ) { for ( i = 6; i >= list ; i--)
{
printf("%c",32);
}
list = list + 1;
/* for creating upper stars*/
for ( f = 1 ; f <= 5 ; f++ ) { for ( q = 9 ; q >= push ; q-- )
{
printf("%c",42);
}
break;
}
push = push - 2;
printf("\n");
}
/*End of first for loop*/
/*Second diamond half starts with spaces*/
for ( a = 1 ; a <= 5 ; a++ )
{
for ( b = 2; b <= c ; b++ )
{
printf("%c",32);
}
c = c + 1 ;
/*Second start of stars*/
for ( n = 1 ; n <= 4 ; n++ )
{
for ( m = 7 ; m >= o ; m-- )
{
printf("%c",42);
}
break;
}
o = o + 2;
printf("\n");
}
}
No comments:
Post a Comment