0

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");
}
2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by Muhammadlodhi
0

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

Edited by gerard4143: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.