1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Naddik [55]
3 years ago
6

Programming challenge description: Write a program that, given two binary numbers represented as strings, prints their sum in bi

nary. The binary strings are comma separated, two per line. The final answer should not have any leading zeroes. In case the answer is zero, just print one zero i.e. 0 Input: Your program should read lines from standard input. Each line contains two binary strings, separated by a comma and no spaces. Output: For each pair of binary numbers print to standard output their binary sum, one per line.
Computers and Technology
1 answer:
Lubov Fominskaja [6]3 years ago
8 0

Answer:

The program to this question can be given as:

Program:

#include<iostream>  //include header file

using namespace std;  

string add(string a, string b)  //define add function

{       //declare variable  

   string result = "";  

   int sum = 0,k,l;      

   cahr x;    

   k= a.size() - 1;

   l = b.size() - 1;  

   while (k>= 0 || l>= 0 || sum == 1) //loop

   {

   //addition 

       sum= sum+ ((k >= 0)? a[k] - '0': 0);  

       sum= sum+ ((l >= 0)? b[l] - '0': 0);

        x=sum%2;

      result=(x+'0') +result;

  // Compute carry

       sum =sum/ 2;  

       // Move to next digits  

       k--;  

       l--;  

   }  

   return result; //return value

}

int main()  //main method  

{  

   string a,b;  //string variable

   cout<<"Enter first binary digit: ";  //message.

   cin>>a;     //input from user

   cout<<"Enter Second binary digit: ";  //message.

   cin>>b;     //input from user

   cout <<"Addition :"<<add(a, b)<<endl; //print addition

   return 0;  

}

Output:

Enter first binary digit: 1101

Enter Second binary digit: 100

Addition :10001

Explanation:

In the above c++ program first, we include the header file. Then we define the add function in the add function we add two binary digits by passing value as arguments. In this function, we define a variable that is used on the addition of binary numbers. In this function we define the loop in the loop we check if two binary number is 1 then it will print 0 and pass 1 as the carry. after performing addition it will return value. In the main function, we take two binary numbers from the user and pass the value to the function and print function return value.

You might be interested in
2) What is the value stored in the variable z by the statements below?
Dmitriy789 [7]

Answer:

7

Explanation:

Because the q.length is a inbuilt function in the programming which used to get the length of the array. In the array, there are 7 values are store. Therefore, the size 7 store in the variable z.

For example:

int[] array={1,2};

int x = array.length;

the answer of above code is 2, because the elements present in the array is 2.

 

5 0
2 years ago
write an expression taht evaluated to true if and only if the variable s does not contain the string 'end'
natima [27]

Answer:

//check which string is greater

if(strcmp(name1,name2)>0)

//assign name1 to first, if the

    //name1 is greater than name2

    first=name1;

else

    //assign name2 to first, if the

    //name2 is greater than name1

    first=name2;

5)

//compare name1 and name2

    if(strcmp(name1,name2)>0)

   

         //compare name1 and name3

         if(strcmp(name1,name3)>0)

       

             //assign name1 to max, becuase

             //name1 is greater than name2 and name3

             max=name1;

       

Explanation:

7 0
2 years ago
Describe two differences between landscape mode and portrait mode. Respond in 2-3 complete sentences.
Mice21 [21]

Answer:

they just are different

Explanation:

3 0
3 years ago
Read 2 more answers
A proactive computer professional will _____. have a neutral outlook toward technology underestimate the impact of technology an
Elodia [21]

Answer:

A proactive computer professional will anticipate future problems and need

Explanation:

This statement is not only true for technology but for any field. Anybody who is proactive will always look for future, will foresee future problems and challenges and get ready to face those. He will simultaneously analyze the present interest and problems and connect the future and prepare himself well to be successful in the future.

For pro-active person’s success is not an end, even after getting succeeded he must work for tomorrow. So thus, the choice is justified with various analytical statement.

4 0
3 years ago
Read 2 more answers
What is an electronic medical record
Airida [17]
EGC . medical research science
3 0
3 years ago
Other questions:
  • Which one of the following media is most resistant to EMI?
    11·1 answer
  • NEED THIS NOW PLEASE!!!! (I AM NOT JOKING I HAVE TO SUBMIT IN 5 MINUTES)
    13·2 answers
  • Commercial applications are never free<br><br> -True<br><br> -False
    9·1 answer
  • Which of the following is a default letter assigned for the primary hard drive
    6·2 answers
  • Security Definition updates for windows defender are performed through the ——— function in windows server 2016
    7·2 answers
  • According to the stage-gate process developed by Robert G. Cooper, _____ are the results of the previous stage and are the input
    15·1 answer
  • Given the three thread states: running, runnable (i.e., ready), and blocked (i.e., waiting), state which of the six possible thr
    13·1 answer
  • Mobile computing is growing in importance each and every day, and the IT manager must take that into account. Do some web resear
    14·1 answer
  • Use the drop-down menus to complete each sentence.
    8·2 answers
  • Create a new data frame, first_south, by subsetting titanic to include instances where a passenger is in the first class cabin (
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!