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
4. True or False? Electrons flow out from the POSITIVE end of a battery. *<br> True<br> False
lana66690 [7]
False electrons put off a negative charge
4 0
3 years ago
What are the programming concepts (within or outside the scope of IT210) that you would like to strengthen and delve into furthe
marin [14]

Answer:

The description for the given question is described in the explanation section below.

Explanation:

I would like to reinforce in advanced or complex concepts such as documents as well as channels, internet programming, multi-threading, after that last lesson.

  • I am interested in learning web development to develop applications or software. I would also like to explore those concepts by using open source tools.
  • Course concepts will have to develop models for handling.
  • No there is no subject matter or definition you provide further clarity for.
  • I'm interested in studying java as well as web development in comparison to C++ so I can use it in my contract work.
4 0
3 years ago
In ____, data can move in both directions at the same time, such as with a telephone.
gtnhenbr [62]

The answer is d. full-duplex transmission. This communication setup allows for simultaneous transmit and receive for both parties. As signals are able to be transmitted at the same time two way for both parties, for both directions along the same data carrier medium.

4 0
3 years ago
Jamie found the ISBN of the book she wanted to order in the Books in Print Catalog. To remember the eleven-digit number, 1977255
algol13

Answer:

Chunking

Explanation:

Chunking refers to the process of taking individual pieces of information (called chunks) and grouping them into larger units. By grouping each piece into a large whole, you can improve the amount of information you can remember.

5 0
3 years ago
Explique dos recursos que necesitan los empresarios para poder poner en práctica sus ideas.
nasty-shy [4]

ESPANOL: La explotación exitosa de nuevas ideas es crucial para que una empresa pueda mejorar sus procesos, traer productos y servicios nuevos y mejorados al mercado, aumentar su eficiencia y, lo más importante, mejorar su rentabilidad.

INGLES: The successful exploitation of new ideas is crucial to a business being able to improve its processes, bring new and improved products and services to market, increase its efficiency and, most importantly, improve its profitability

8 0
2 years ago
Read 2 more answers
Other questions:
  • The following is true about SPAM ________.
    9·1 answer
  • The ____ function sums the numbers in the specified range and then divides the sum by the number of cells with numeric values in
    14·1 answer
  • Assume you have a project with seven activities labeled A-G (following). Derive the earliest completion time (or early finish-EF
    15·1 answer
  • 13. You're expecting an important call from Mr. Suarez, a potential customer. While waiting for this call, your supervisor calls
    15·1 answer
  • What is <br> central vision
    12·2 answers
  • Instead of terminating the series, the producers decided to extend it for an additional season. In the sentence above, which of
    13·1 answer
  • List the gcc command-line options for each of the following: Generate a .o file rather than an executable. Generate a .s (assemb
    6·1 answer
  • Compare gigabytes GB, kilobytes and terabytes.​
    11·1 answer
  • A data analyst adds descriptive headers to columns of data in a spreadsheet. How does this improve the spreadsheet?.
    8·1 answer
  • How do u type please help
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!