Write the code which will print out this
1
232
34543
4567654
567898765
67890109876
7890123210987
890123454321098
90123456765432109
0123456789876543210
Printable View
Write the code which will print out this
1
232
34543
4567654
567898765
67890109876
7890123210987
890123454321098
90123456765432109
0123456789876543210
And nicely formatted as well:
Code:#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);
}
:D Cool parksie! :D
I already had that code stashed away because I got a question for that emailed to me through AllExperts :)
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..
Quote:
Write the code which will print out this
You didn't specify how :)Code: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're such a cheeky git, Megatron :p
Nice attitude tho :D
:DI knew somebody will post thatQuote:
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;
How does your function work, Parksie? )just dont get it :(
I don't know...I wrote it quite a while ago -- try stepping through it with the debugger.
ok