Results 1 to 11 of 11

Thread: Interesting Task

  1. #1

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Write the code which will print out this


    1
    232
    34543
    4567654
    567898765
    67890109876
    7890123210987
    890123454321098
    90123456765432109
    0123456789876543210
    Last edited by Vlatko; Apr 2nd, 2001 at 05:26 AM.
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  2. #2
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    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);
    }
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  3. #3

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    Cool parksie!
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  4. #4
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I already had that code stashed away because I got a question for that emailed to me through AllExperts
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  5. #5

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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..
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  6. #6
    Guest
    Write the code which will print out this
    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 didn't specify how

  7. #7
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    You're such a cheeky git, Megatron

    Nice attitude tho
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  8. #8

    Thread Starter
    Frenzied Member Vlatko's Avatar
    Join Date
    Aug 2000
    Location
    Skopje, Macedonia
    Posts
    1,409
    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;
    I knew somebody will post that
    I am become death, the destroyer of worlds.
    mail:[email protected]

    • Visual Basic 6.0 & .NET
    • Visual C++ 6.0 & .NET
    • ASP
    • LISP
    • PROLOG
    • C
    • Pascal

  9. #9
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Question ??

    How does your function work, Parksie? )just dont get it
    Amon Ra
    The Power of Learning.

  10. #10
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    I don't know...I wrote it quite a while ago -- try stepping through it with the debugger.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

  11. #11
    Hyperactive Member Amon Ra's Avatar
    Join Date
    Feb 2001
    Location
    In some cave on Uranus...
    Posts
    500

    Unhappy ok

    ok
    Amon Ra
    The Power of Learning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width