please solve this in easy way....

1
232
34543
4567654
567898765
Solve what?
6789aba9876
789abcdcba987
89abcdefedcba98

?
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <iostream>
using std::cout;
using std::endl;

int main()
{
    int i;
    int j = 0;
    int num = 2;
    int decrementOffset = 0;
    int counter = 1;

    for(i = 1; i < 6; i++)
    {
            for(j = i; j < num; j++)
            {
                    ///If the loop is on the second row or higher
                    if(i > 1)
                    {
                        ///If the value of J is the highest for that row, start decrmenting
                        if(j >= num - counter)
                        {
                            decrementOffset += 2;
                        }
                    }

                    cout<<j-decrementOffset;
                    counter += 1;
            }

        cout<<endl;
        num += 3;///increases the length of the row each loop

        ///resets variables
        decrementOffset = 0;
        counter = 0;
    }
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <iostream>
#include <sstream>
#include <string>
#include <limits>
#include <ios>

using namespace std;

int main()
{
	stringstream seq;
	int j = 1;
	int k = 0;

	for(int i = 1; i < 6; i++)
	{
		seq << i;
		
		j = 1;
		while(j < i)
		{
			k = i + j;
			seq << k;
			j++;
		}

		while(k > i)
		{
			seq << k - 1;
			k--;
		}
		
		seq << std::endl;
	}

	std::cout<<seq.str();
        std::cout<<"Press Enter to exit";
	std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
	return 0;
};



1
232
34543
4567654
567898765
Press Enter to exit
Last edited on
Do you mean this?
1
2
3
4
5
6
7
#include <iostream>

int main()
{
    std::cout << "1\n" "232\n" "34543\n" "4567654\n" "567898765";
    return 0;
}


or this?
1
2
3
4
5
6
7
8
9
#include <iostream>

int main()
{
    for (int i = 0; i < 5; ++i)  //5 lines
        for (int j = 0; j < 2*i+1; ++j)
            std::cout << (j>i ? 3*i-j : i+j)+1 << (j==2*i ? "\n" : "");
  return 0;
}

6789aba9876
789abcdcba987
89abcdefedcba98

?


LOL!
@txtxtnt

What does the question mark and the colon do in line 7???
What does the question mark and the colon do

See "Conditional operator" on this page: http://www.cplusplus.com/doc/tutorial/operators/
Also known as the "Ternary Operator" as it takes three terms.
@ Chervil

Thanks
Topic archived. No new replies allowed.