-
problem with the program
Code:
#include<stdio.h>
main()
{
int i,j;
for(i=0;i<5;i++)
printf("\n");
for(j=0;j<5;j++)
{
if(i>=j)
printf("* ");
else
printf(" ");
}
}
i want to get output as
*
**
***
****
*****
but the above code did not work....please help me where it went wrong.....
-
There is no need of the else statement and you have misplaced the printf("\n"); statement. It should be at the end of the first for loop.
-
you do not need if at all, just make the inner loop
-
A couple of issues with your program are the following:
1. Never use simple main. Use int main(void) and make sure you return 0 at the end of the program.
2. With the above program there are a lot of problems.
[insert]
Code:
#include<stdio.h>
main()
{
int i,j;
for(i=0;i<5;i++)
printf("\n");
for(j=0;j<5;j++)
{
if(i>=j)
printf("* ");
else
printf(" ");
}
}
Your first for loop is not having any {}. So its scope is just to the next line. And instead of the second for loop do the following
So it should be like this
[insert]
Code:
for(i=0;i<5;i++)
{
printf("\n");
for(j=0;j<= i;j++)
{
printf("* ");
}
}
-
thanks a lottt to u all.........now its working......