1.11M Members

Print star pattern

 
0
 

Hi,

I would like to print star pattern in the following way -

****
***
**
*

main()

int i;

clrscr();

for(i=4;i<=4;i++)

{

printf("*");

getch();

}

It prints starts like ****

I don't know how to complete the program. Can anyone please do the complete program for this so that stars are printed in the manner as given above.

Thanks

 
0
 

try two for loops...one embedded into the other

for (i = 0; i < num; ++i)
{
for (j = 0; j < num2; ++j)
{}
}
 
0
 

try two for loops...one embedded into the other

for (i = 0; i < num; ++i)
{
for (j = 0; j < num2; ++j)
{}
}

Thanks for quick reply. What do you mean by num and num2 in the above code. Will i have to declare num and num2.

 
0
 

Thanks for quick reply. What do you mean by num and num2 in the above code. Will i have to declare num and num2.

Its just an example that I made up..The numbers signify nothing.

 
1
 

Its just an example that I made up..The numbers signify nothing.

It doesn't matter, if she follows your advise she will get a square.

Can anyone please do the complete program for this so that stars are printed in the manner as given above.

Then you'll learn nothing.

Some clue:
One loop inside another one as previously said.
Outer loop is the number of rows.
Inside loop number of stars for each row printed minus one less than previous row.

 
-1
 

Hi,

I would like to print star pattern in the following way -

****
***
**
*

main()

int i;

clrscr();

for(i=4;i<=4;i++)

{

printf("*");

getch();

}

It prints starts like ****

I don't know how to complete the program. Can anyone please do the complete program for this so that stars are printed in the manner as given above.

Thanks

hey u may try this..
#include<stdio.h>
#include<conio.h>
void main()
{int i,j;
clrscr();
for(i=1;i<=4;i++)
{
for(j=1;j<=5-i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

 
-2
 
void main()
{
         int i,j;
         clrscr();
         for(i=4;i>=1;i--)
         {
             printf("\n");
             for(j=1;j<=i;j++)
                printf("*");
          }
}
You
This article has been dead for over six months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article