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 to insert Section Break in Microsoft word 2016 ?
aivan3 [116]

Answer:

C. Layout Tab – Page setup group – Breaks – Next page button.

3 0
3 years ago
WordArt styles allow you to add ____.
maria [59]
As for this problem, the most probable and the most likely answer to this would be it depends on the person or the user of it since there aren't any options presented with the problem.

WordArt is there to be of use during presentations, during discussions, and other things. On the other hand, as the technological advancement takes leaps and bounds going forward, this utility seems to be underused and isn't expected to give a more impact to the reader or to the recipient of such document that contains it. This is typically used for people that aren't too familiar yet, as to how to utilize other programs to enhance their documents and files.
3 0
3 years ago
The listing of a directory shows certain files with permissions set to rwsr-xr-x. what does this indicate?
marta [7]
<span>"rws" means that the user has permissions to read, write and setuid. "r" means the user can read the file and "w" means that the user can write to the file. "s" stands for "setuid" (set user id) is a permission bit that allows the users to execute a program with the permissions of its owner. The "s" can also mean "setgid" (set group id) is a bit that allows the user to execute a program with the permissions of the group owner.</span>
5 0
3 years ago
5.2
Ray Of Light [21]

Answer:

In order to reduce the risk of accidents on the roads.

Explanation:

The special equipment is used when  testing eyesight for a driver's license in order to reduce the risk of accidents on the roads. Good eyesight is very important for good and safe driving so to find out the eyesight of the driver, the license officer used special equipment in order to check driver's eyes. If the eyesight is good, the officer provide license to the person otherwise not so that no accidents happen on the road.

8 0
2 years ago
What is the name of the book farrah gray published in 2005??
seropon [69]
He wrote Reallionaire
8 0
3 years ago
Other questions:
  • Why is the protocol down, even though you issued the no shutdown command for interface vlan 99?
    5·2 answers
  • According to the family life course development framework, the __________ stage of the family life cycle comes to an end with th
    7·1 answer
  • Write a function called calculate() that accepts three integer Numbers as arguments, compute these values : Sum and Product and
    7·1 answer
  • The right headlight does not function on either high or low beam. Technician A says this could be caused by an open ground on th
    12·1 answer
  • Please Help!! How to code this in Python?
    11·1 answer
  • TWO MINUTES LEFT<br> ________ __________ is the physical arrangement of devices on a network.
    9·1 answer
  • Write a program that prompts the user to enter their name store this value in a variable called name Prompt the user for their c
    10·1 answer
  • Term of The surroundings and conditions of your workplace
    6·1 answer
  • Raw materials have two basic types what are the 2?
    11·2 answers
  • Which generation computer supported GUI operating system?​
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!