star pattern

mrunalini's Avatar, Join Date: Aug 2009
Light Poster
Q: Genrate star pattern below
Code:
  *               *
  *   *       *   *
  *   *   *   *   *
Program:
Code:
main()                                                                        
{                                                                             
        int a=3,i,j;                                                    
        char k='*';                                                   
        clrscr();                                             
        for(i=1;i<=3;i++)                                                     
        {                                                                     
                for(j=1;j<=i;j++ )                                            
                printf("%3c",k);                                              
                for(j=1;j<=a;j++)                                             
                printf("   ");                                                
                a-=2;                                                        
                for(j=1;j<=i;j++)                                             
                printf("%3c",k);                                              
                printf("\n");                                               
        }
getch();      
}
O/P:
Code:
  *                 *
  *  *         *  *
  * *   *    *  *  *
This is the o/p i m getting what should be done to remove this one extra star in last line.
if i put "j<=2" in last for loop check condition then this extra star moves in first row like this

O/P:
Code:
  *                 *  *
  *  *         *  *
  *  *   *    *  *
so plz suggest right solution to get desired o/p.

Last edited by SaswatPadhi; 21Nov2009 at 17:33.. Reason: Code blocks
0
mrunalini's Avatar, Join Date: Aug 2009
Light Poster
Q: Genrate star pattern below like crown
total 3 rows ,
and 5 columns,
5stars in 3rd row ,
2stars on right and 2stars on left side i.e total 4 stars in 2nd row,
1star on right and 1 star on left side i.e. total 2 stars in 1 st row,
* *
* * * *
* * * * *
__________________________________________________
Program:
Coding:
main()
{
int a=3,i,j;
char k='*';
clrscr();
for(i=1;i<=3;i++)
{
for(j=1;j<=i;j++ )
printf("%3c",k);
for(j=1;j<=a;j++)
printf(" ");
a-=2;
for(j=1;j<=i;j++)
printf("%3c",k);
printf("\n");
}
getch();
}
O/P:
* *
* * * *
* * * * * * This is the o/p i m getting what should be done to remove this one extra star in last line.
if i put "j<=2" in last for loop check condition then this extra star moves in first row like this
O/P:
* * *
* * * *
* * * * *
so plz suggest right solution to get desired o/p.




[/quote]
0
shabbir's Avatar, Join Date: Jul 2004
Go4Expert Founder
Code Blocks you should use.