Output required

Hello all,

Well i wanted a output of a prorgram to look like this, i tried but can't figured out the logic, can anyone plesae help me out here with this

1
232
34543
4567654
567898765
Look at each line (or column) individually...

1

2 3 2

3 4 5 4 3

4 5 6 7 6 4

5 6 7 8 9 8 7 6 5
This would do it too. :)

int _tmain(int argc, _TCHAR* argv[])
{
char* str =
" 1 \n"
" 232 \n"
" 34543 \n"
" 4567654 \n"
"567898765\n";

printf(str);

return 0;
}

Berk Celebisoy
Software Developer - Microsoft Corp.
Last edited on
I assume his instructor (sounds like an assignment to me) wants a loop or something similar to be used so that it can be shown that they understand the logic behind the triangle...
Last edited on
Software Developer - Microsoft Corp.

Oh, well that explains it.
(from) Microsoft :)) :))

Good one :)
@yousufrafi

You have to think about how the number of spaces and the number of digits relate to a loop.

You will need a loop to count through the number of lines.
Then you will need one or more "inside" loops to count off the spaces/letters to print.

Whenever I have to make characters line up a specifc way on the screen, I find it helpful to get out a piece of graph paper and a pencil and draw what I want to see, then count cells so I know how many times I need to loop, etc.

Good luck!

@berkcan
There is a reason this forum doesn't have signatures. Please observe it.
i hope this code can help

#include <iostream>

using namespace std;

int main()
{
int n;
cout << "Input n : "; cin >> n;

int middle = 1;
int space;
space = n - 1;

for (int i=1; i<=n; i++)
{
if (i>1)
{
middle = i + (i-1);
}

for (int s = 1; s<=space; s++)
{
cout << " ";
}
--space;

for (int j=i; j<=middle ; j++)
{
cout << j ;
}
for (int j=middle-1; j>=i ; j--)
{
cout << j ;
}
cout << endl;
}

cin.sync();
cin.get();
return 0;
}
vcc, do you want to work with the guy the company hired that has no idea what he is doing?
What Duoas means by that is that you shouldn't just give them the code for it because then they'll never learn how to do it themselves and as soon as a problem comes along that they haven't done before, they won't be able to solve it.
Topic archived. No new replies allowed.