[ create a new paste ] login | about

Link: http://codepad.org/QeE2PgWa    [ raw code | fork ]

iamyeasin - C, pasted on Jul 2:
#include<bits/stdc++.h>
#define sf scanf
#define pf printf

using namespace std;


int main()
{
    int matrix[500][500],n;

    while(sf("%d",&n),n)
    {
        if(n==1)
        {
            pf("1\n\n");
            continue;
        }
        else if( n==2 )
        {
            pf("1 2\n2 4\n\n");
            continue;
        }
        else
        {
            long long  big = pow(n,n);
            int xx = 0;
            while(big > 0)
            {
                big /= 10; xx++;
            }
//            cout << big << " " << xx << endl;
            int x=1,ans,flag=1,y=1;
            for(int i=1; i<=n; i++)
            {
                for(int j=y,k=1; k<=n; j*=2,k++)
                {
                    int nn=j,dg=0;
                    while(nn>0)
                    {
                        nn/=10; dg++;
                    }

//                    cout << "xx = " << xx << " dg = " << dg<< endl <<endl<<endl;;
                    if(k==1)
                    {
//                        cout << big << " " << dg << endl;
                        for(int m=1; m <=(xx-dg); m++)
                        {
                            pf(" ");
                        }
                        pf("%d",j);
                    }
                    else if(k != n && k != 1)
                    {
                        for(int mn=1; mn<=(xx-dg); mn++)
                        {
                            pf(" ");
                        }
                        pf("%d",j);
                    }
                    else if(k==n)
                    {
//                        cout << endl << "xx = "  << xx << " dg = " << dg << endl;
                        for(int mn = 1; mn<=(xx-dg); mn++)
                        {
                            pf(" ");
                        }
                        pf("%d\n",j);
                    }
                }
                y *= 2;
                pf("\n");
            }

        }

    }


    return 0;
}


Create a new paste based on this one


Comments: