mardi 29 novembre 2016

Facing Runtime error in an online judge

program need to show the binary value of a number and total number of 1.

Badly looking for a solution of runtime error.

When I run and test the program with different test cases , it looks good. But , when I submit this code to uva as c++ or c++11 , it shows runtime error. Not only this program, but also some other problems too. Here is the body of one program.

long long int a[100],i,n=0;
    for(i=0; ;i++,n++)
    {
        cin >> a[i];
        if(a[i]==0)
            break;
    }
    for(i=0;i<n;i++)
    {
        long long int r[100],t=0,j=0,one=0;
        while(a[i]!=0) {
            r[j]=a[i]%2;
            a[i]/=2;
            if(r[j]==1)
                one++;
            j++;
            t++;
        }
        for(j=t-1;j>=0;j--)
            cout << r[j];
        cout <<" One's "<< one << endl;

Aucun commentaire:

Enregistrer un commentaire