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]
4 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]4 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
Which of these is an effective color scheme? A. red text on black background B. red text on red background C. yellow text on bl
Natasha2012 [34]
Effectively, Yellow text on a black background would show up the best.
The contrast of the bright and dark would be the best for people to see.

Hope this helps!

3 0
3 years ago
Read 2 more answers
The technique helps you explore possible risks by providing access to risk areas identified in the past. It also provides the so
Elza [17]

Answer:

The technique helps you explore possible risks by providing access to risk areas identified in the past is explained below in details.

Explanation:

Risk administration commences with the system of classifying risks. In this method, we examine future developments or circumstances that may influence our understanding and capacity to accomplish our aims. Risk identification incorporates estimating out where, when, how, and why such situations may happen.

7 0
3 years ago
_____ should be used to create a project schedule.
dem82 [27]

Answer:

meeting is the correct answer

3 0
4 years ago
In which view can you see speaker notes?
Bond [772]

Answer:

c. notes view

Explanation:

Assuming you're talking about a slideshow program, like Microsoft PowerPoint, the notes view lets you see the speaker notes.

The normal view is the one used normally to present the regular slideshow content, it's formatted for a screen view.

The handout view is same as normal view, but formatted for print.

The slide sorter view is a general overview of your presentation allowing you to move your pages around.

4 0
3 years ago
You are a web designer, and a client wants you to create a website for their new business. Discuss what you would talk about wit
spin [16.1K]

Answer:

1. for what purpose?

2. the pattern design of web

3. what the client wants to add in the web

4. his contact number and email

5. the logo of the business

6. talk about pricing  

Explanation:

7 0
3 years ago
Other questions:
  • You are setting up your Windows computer to connect to the Internet and notice that when you type www.microsoft, the browser doe
    8·1 answer
  • Which of the following is the correct code to link the text "Sunny Days" to the website www.sunnysunshine.com?
    15·1 answer
  • Write a file path for a document file that is saved on the F drive then a folder called homework, then a folder called math. The
    12·1 answer
  • Select the correct answer from each drop-down menu.
    7·2 answers
  • Which describes the first step a crawler-based search engine uses to find information?
    10·2 answers
  • Which XXX will prompt the user to enter a value greater than 10, until a value that is greater than 10 is actually input?
    14·1 answer
  • What is NOT a built-in function in python?<br> sqrt()<br> string()<br> fabs()<br> O print()
    12·2 answers
  • Please help! Answers that do not relate to this topic will be REPORTED!
    11·1 answer
  • An outpatient provides the following id: barbara jones, birth date 8/15/63. should a specimen be collected for this lab order?
    11·1 answer
  • Explain external interface bus
    7·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!