what's the problem in my coding
I want to get the following output
1
12
123
1234
12345
and here's my coding
1 2 3 4 5 6 7 8
|
#include<iostream.h>
#include<conio.h>
void main()
{clrscr();
for (int i=1;i<=5;i++)
{for(int j=1;j<=i;j++)
cout<<j<<endl;}
getch();}
| |
and i am getting
the following
1
1
2
1
2
3
1
2
3
4
1
2
3
4
5
what 2 do
Last edited on
Your problem is that
endl incudes a newline, so yuo only want it in the outer loop, not the inner loop.
1 2 3 4 5 6 7 8
|
for (int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
cout<<j;
}
count << endl; //Note to self: Learn to type:-)
}
| |
Last edited on
well faldrax the program is still not working & displaying the same
Faldrax's code is correct except for an extra 'n' on line 7:
Last edited on
this will help you out here!!!
1 2 3 4 5 6 7 8 9 10 11 12 13
|
int main()
{
for (int i=1;i<=5;i++)
{
for(int j=1;j<=i;j++)
{
cout<<j;
}
cout << endl;
}
return 0;
}
| |
Last edited on
Topic archived. No new replies allowed.