Thread: A beginner's code_code-2_1.121.12321...

  1. #1
    Registered User sumitsatsangi's Avatar
    Join Date
    Jan 2012
    Posts
    5

    Question A beginner's code_code-2_1.121.12321...

    One more in the row... hope this time it is good...

    - Sumit

    Code:
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
        int a, b, c, x;
        cout<<"Please input the number: ";
        cin>>x;
        for(a=1;a<=x;a++)
            {
                for(b=1;(x-b)>=a;b++)
                    cout<<" ";
                for(c=1;c<=a;c++)
                    cout<<c;
                for(b=1;b<a;b++)
                    cout<<(a-b);
            cout<<endl;
            }
    }

  2. #2
    Registered User sumitsatsangi's Avatar
    Join Date
    Jan 2012
    Posts
    5
    Okay, I have another code which I wrote first, which I found last night... Once again, the same dilemma, which is better. I understand that the one I mentioned first is better.

    Kindly enlighten.

    Code:
    #include<iostream>
    
    using namespace std;
    
    int main()
    {
        int a, b, c, x;
        cout<<"Please input the number: ";
        cin>>x;
        for(a=1;a<=x;a++)
            {
                for(b=1;(x-b)>=a;b++)
                    cout<<" ";
                for(c=1;((x+1)-c)>=b;c++)
                    cout<<c;
                for(c=c-2;c>=1;c--)
                    cout<<c;
            cout<<endl;
            }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. i am a beginner
    By alperen1994 in forum C Programming
    Replies: 2
    Last Post: 03-13-2009, 03:15 PM
  2. Windows programming for beginner (Absolute beginner)
    By WDT in forum Windows Programming
    Replies: 4
    Last Post: 01-06-2004, 11:21 AM
  3. Help (Beginner)
    By NewbieC in forum C++ Programming
    Replies: 9
    Last Post: 01-29-2003, 02:26 PM
  4. please help a beginner
    By karen66 in forum C Programming
    Replies: 5
    Last Post: 12-16-2002, 07:02 AM
  5. A beginner in need
    By pneumo45 in forum C++ Programming
    Replies: 3
    Last Post: 06-11-2002, 10:17 PM