View Single Post
Old 19-09-2007, 08:17 PM   #184 (permalink)
QwertyManiac
Commander in Chief
 
QwertyManiac's Avatar
 
Join Date: Jul 2005
Posts: 6,658
Default Re: Post ur C/C++ Programs Here

Quote:
Originally Posted by nithinks
Okay another challenge ..
Can you write a C program to print the number in the format given below?



and so on
Don't think mine's so efficient but it kind of does the job:

Code:
#include<iostream>

using namespace std;

/*

            1
           323
          43234
         5432345

*/

int main()
    {
        int count = 1, temp=1, i, j, k;
        
        for(int times=1;times<5;times++)
            {
                for(i=5;i>=times;i--)
                    {
                        cout<<" ";
                        if(i==1)
                            {
                                cout<<1;
                            }                        
                    }
                    
                for(k=temp;k>=2;k--)
                    {
                        cout<<k;
                    }
                
                
                    
                for(j=3;j<=temp;j++)
                    {
                        cout<<j;
                    }
                
                if(temp==1)
                    {
                        temp+=2;
                    }
                else
                    {
                        temp++;
                    }
                
                count+=1;
                    
                cout<<endl;
            }
    }
__________________
Harsh J
www.harshj.com
QwertyManiac is offline