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
How important are operating system in our devices?​
TiliK225 [7]

Answer:

Explanation:

An operating system is the most important software that runs on a computer. ... It also allows you to communicate with the computer without knowing how to speak the computer's language. Without an operating system, a computer is useless.

6 0
2 years ago
Read 2 more answers
What command launches the remote desktop client for windows?
Ksju [112]
%windir%\system32\mstsc.exe

launches the RDP client.
7 0
3 years ago
Fire stick optimizing system storage and applications
vivado [14]

Answer:

IN MY PROFILE

Explanation:

I HAVE AWNSERED THIS QUESTION THROUGHOUT MY BEING HERE PLEASE DO NOT BE AFRAID TO CLICK ON MY PROFILE AND FIND THE ANSWER

5 0
2 years ago
Which term refers to the data stored in computer memory on which the processor applies to program instructions
Fed [463]
The answer is B.) variable.
3 0
3 years ago
BITS wants to store information about the supervisors, including their supervisor number and the relationship to consultants. Su
Olin [163]

Answer:

Convert the table into normalize form

Explanation:

Un normalized relation of the given schedule is as

Consultant ( ConsultNum, Last Name, First Name, Street, City, ZipCode

HoursRate (SupervisorNum, Supervisor Num)

(Tasks, Description, Catagory, Price, SupervisorNum))

According to these functional dependencies :

SupervisorNum is dependencies of the SupervisiorNum

ConsltNum is dependencies of the Last Name, First Name, Street, City, ZipCode, Hours, Rate

Tasks are dependencies of Description, Category, Price

The consultant table is not in a normalized form as it contains repeating groups. Make composite keys such as Supervisor Num, Tasks and ConsltNum and convert the table in NF by removing repeating groups

Such as table in NF

Consultant

(Consult Num, Last Name, First Name, Street, City, Zip Code, Hours, Rate

Supervisor Num, Supervisor Name, Tasks, Description, Category, Price)              

5 0
3 years ago
Other questions:
  • Values that are sent into a function are called _________.<br><br> Program Output
    7·1 answer
  • Describe how using active listening at work can help you be a better employee.
    15·1 answer
  • Is it just me or is brainly not working right now? I am trying to add friends and it won't let me!
    5·2 answers
  • 6.
    14·2 answers
  • The machine should not be oiled until the
    11·1 answer
  • Given four inputs: a, b, c &amp; d, where (a, b) represents a 2-bit unsigned binary number X; and (c, d) represents a 2-bit unsi
    6·1 answer
  • What was your learning target for today
    9·2 answers
  • Does anyone know what to do when brainly won't let you answer questions? I click on answer question and then it just sits there
    15·2 answers
  • The Internet is based on a U.S. government project called ________. Today, the Internet is a collection of networks, tied togeth
    5·1 answer
  • What is operating system​
    10·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!