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

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

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

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.

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.

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.

Edited 7 Years Ago by Aia: n/a

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();
}

Comments
yet another useless bump, no code tags, void main PoS
void main()
{
         int i,j;
         clrscr();
         for(i=4;i>=1;i--)
         {
             printf("\n");
             for(j=1;j<=i;j++)
                printf("*");
          }
}

Edited 3 Years Ago by Dani: Formatting fixed

Comments
yet another useless bump, no code tags, void main PoS
Bad Code, Resurrecting old thread, no code tags. Now all you need is a link to Viagra.
This article has been dead for over six months. Start a new discussion instead.