My binary addition code is stuck.VS code shows high usage but its not printing anymore

Viewed 25

Here's my code '''

#include<iostream>
using namespace std;

int reverese(int i){
    int rev=0;
    while(i>=0){
        rev=rev*10+(i%10);
        i/=10;
    }
    return rev;
}

int main(){
    int a,b,sum=1,carry;
    cout<<"Enter First Binary Number\t:\t";
    cin>>a;
    cout<<"Enter Second Binary Number\t:\t";
    cin>>b;
    carry=0;
    while(a>0 || b>0){
    if (a%2==0 && b%2==0){
        sum=sum*10+carry;
        carry=0;
        a/=10;b/=10;
    }else if((a%2==1 && b%2==1)){
        sum=sum*10+carry;
        carry=1;
        a/=10;b/=10;
    }else{
        if (carry==1){
            sum=sum*10+0;
        }else{
            sum=sum*10+1;
        }
        a/=10;b/=10;
    }
    }
    if(carry==1){
        sum=sum*10+1;
    }
    sum=reverese(sum)-1;
    cout<<"\n Sum\t:\t"<<sum<<endl;
    return 0;

} ''' and here is where it is stuck: Terminal

vs code shows very high power usage task manager

I've left it on for quit some time but it's still stuck at the same screen

0 Answers
Related