This is what i've made so far.

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
	int b=1;

	for (int i=1; i<=5; i++)
	{
		for (int k=1; k<=i; k++)
		{
		 cout<<b;
		 b++;
		}
		cout<<endl;
    }

	getch();
	return 0;
}

The output is as below

1
23
456
78910
1112131415

The correct one should be:

1
12
123
12
1

Any help would be greatly appreciated.

Try restarting b at 1 for every iteration of the outer loop. And instead of one loop counting to 5, consider using two loops: one counting up to 3 and one counting down from 2.

thanks.. finally i've made it to display the correct output.

This is how it looks like

#include <iostream>
#include <conio.h>

using namespace std;

int main()
{
	int b=1, d=1;


	for (int j=1; j<=3; j++)
	{
		for (int k=1; k<=j; k++)
		{
			cout<<b;
			b++;
		}
		cout<<endl;
		b=1;
	}

	for (int c=2; c>=0; c--)
	{
		for (int a=1; a<=c; a++)
		{
			cout<<d;
			d++;
		}
		cout<<endl;
		d=1;
	}

	getch();
	return 0;
	
}

Edited 5 Years Ago by aloi93: n/a

Comments
OK.....

Yes here is some problems in your code.You have to update your code like.....

#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
    int i,j;
    cout<<"1";
    cout<<endl;
    for(i=1;i<5;i++)
    {
                    int k=1;
                    for(j=1;j<i;j++)
                    {while(k<=i)
                    {cout<<k;
                    k++;
                    }
                    }cout<<endl;
                    }
                    
                    getch();
                    return 0;
                    }
This question has already been answered. Start a new discussion instead.