PDA

Click to See Complete Forum and Search --> : Interesting Task


Vlatko
Apr 2nd, 2001, 05:20 AM
Write the code which will print out this


1
232
34543
4567654
567898765
67890109876
7890123210987
890123454321098
90123456765432109
0123456789876543210

parksie
Apr 2nd, 2001, 05:33 AM
And nicely formatted as well:

#include <iostream>

using namespace std;

int MyTrunc(int iNum) {
int temp = iNum;
while(temp >= 10) temp -= 10;
return temp;
}

void DrawPyramid(int iMaxOuter) {
for(int i = 1; i <= iMaxOuter; i++) {
for(int j = i; j < iMaxOuter; j++) {
cout << " ";
}

if(i == 1) {
cout << "1";
} else {
for(j = 0; j < i; j++) {
cout << MyTrunc(i+j);
}
for(j = i-2; j >= 0; j--) {
cout << MyTrunc(i+j);
}
}
cout << endl;
}
}

void main() {
DrawPyramid(10);
}

Vlatko
Apr 2nd, 2001, 12:09 PM
:D Cool parksie! :D

parksie
Apr 2nd, 2001, 12:16 PM
I already had that code stashed away because I got a question for that emailed to me through AllExperts :)

Vlatko
Apr 2nd, 2001, 12:32 PM
I was looking at some old C book from my uncle and saw some pyramid stuff. This seemed very interesting and so i posted it..

Apr 2nd, 2001, 04:08 PM
Write the code which will print out this


cout << "1" << endl;
cout << "232" << endl;
cout << "34543" << endl;
cout << "4567654" << endl;
cout << "567898765" << endl;
cout << "67890109876" << endl;
cout << "7890123210987" << endl;
cout << "890123454321098" << endl;
cout << "90123456765432109" << endl;
cout << "0123456789876543210" << endl;

You didn't specify how :)

parksie
Apr 2nd, 2001, 04:12 PM
You're such a cheeky git, Megatron :p

Nice attitude tho :D

Vlatko
Apr 3rd, 2001, 04:04 AM
cout << "1" << endl;
cout << "232" << endl;
cout << "34543" << endl;
cout << "4567654" << endl;
cout << "567898765" << endl;
cout << "67890109876" << endl;
cout << "7890123210987" << endl;
cout << "890123454321098" << endl;
cout << "90123456765432109" << endl;
cout << "0123456789876543210" << endl;

:DI knew somebody will post that

Amon Ra
Apr 3rd, 2001, 10:33 PM
How does your function work, Parksie? )just dont get it :(

parksie
Apr 4th, 2001, 04:24 AM
I don't know...I wrote it quite a while ago -- try stepping through it with the debugger.

Amon Ra
Apr 4th, 2001, 08:05 PM
ok