Hi .. i want to print this pattern of number using loops . if input is 5 then output should be ...

155555
224444
333333
444422
555551

i have solved

1
22
333
4444
55555

but another reflection is not coming in my mind ... and making me confuse need your help . My code for the half is

#include <iostream>
using namespace std;
int main(){
    int n=5,i;
    for(i=1;i<=n;i++)
    {
    for(int a=1;a<=i;a++)
    {
    cout<<i;
   }
                  
    cout<<endl;
}
    system("pause");
}

Recommended Answers

All 2 Replies

You need to add an extra for loop like below.

#include <iostream>

using namespace std;

int main()
{
	for (int i = 0; i < 5; ++i)
	{
		for (int j = i + 1; j > 0; --j)
		{
			cout << i + 1;
		}
		for (int j = 5 - i - 1; j > 0; --j)
		{
			cout << 5 - i;
		}
		cout << 5 - i;
		cout << endl;
	}
	return 0;
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.