add two binary numbers with array user take number

  add, binary, c++

**User Enter two Decimal Number then convert in binary
and add binary numbers and display decimal.Plz Help me in this case I’m using array.

int a[60],b[60],result[50];

array cannot execute properly.**

         #include <iostream>
        using namespace std
        class Binary {
            private:
           int m,n,i=0,j=0,carry;
           int a[60],b[60],result[50];
           public:
        void get_values() {
           cout<<"Enter first number: "<<endl;
           cin>>m;
           cout<<"Enter second number: "<<endl;
           cin>>n;
        for(i=0 m>0 i++){
            a[i]=m%2;
            m = m/2;
        }
        for(j=0 n>0 j++){
            b[j]=n%2;
            n = n/2;
        }

This code is Decimal to Binary

            cout<<"Binary of the first number: "<<endl;
        for(i=i-1 i>=0 i--){
            cout<<a[i];
            if(i==0) {
            cout<<endl ;}
        }
            cout<<"Binary of the second number: "<<endl;
        for(j=j-1 j>=0 j--){
            cout<<b[j];
            if(j==0) {
            cout<<endl;
            }
        }
**This is Addition Code i mistake this program**
     while (a[i] != 0 || b[j] != 0)
        {
            result[i++] =((a[i] % 10 + b[j] % 10 + carry) % 2);
            carry =((a[i] % 10 + b[j] % 10 + carry) / 2);
            a[i] = a[i] / 10;
            b[j] = b[j] / 10;
        }
            if (carry != 0)
            {
                result[i++] = carry;
            }
                --i;
                cout<<"Sum of two binary numbers: ";
                while (i >= 1)
                cout<<" "<<result[--i];
           }  
          };

Source: Windows Questions C++

LEAVE A COMMENT