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
c++ Write a for loop that computes the following sum: 5+10+15+20+...+485+490+495+500. The sum should be placed in a variable sum
ElenaW [278]

Answer:

#include <iostream>

#include <cstdlib>

 

using namespace std;

 

int main(){

 

 

   int sum=0, num=5;   //variables declaration and inicialization

 

   while (sum<500){   //conditioning to do the sum up to 500

   sum=sum+num;     //actually sum process

   cout << "The value is: "<<sum;   //show the result in screen

   };

   return 0;

}

5 0
4 years ago
All computers can support multiple internal hard drives. <br><br> a. True <br><br> b. False
lara31 [8.8K]
False.  Some can, but some do not have space for them.  Please mark Brainliest!!!
5 0
3 years ago
Free brainliest. really in a good mood today​
Ksivusya [100]

hello, how are you today?

8 0
3 years ago
Read 2 more answers
When you login to your blogging account. The first screen with all controls, tools and functions is called .... Select one: a. D
Artist 52 [7]

Answer:

a. dashboard

Explanation:

In almost every program or webpage where you log in with a personal account. The first screen that contains all your pertinent information and the controls/tools for your account is known as the dashboard. Here you are able to adjust, modify, fix, and analyze all aspects of your account, including the data it contains. The dashboard is extremely useful and often times a necessity for every application.

7 0
3 years ago
What is the reason of non-deterministic (indeterminate) behavior of concurrent programs?
murzikaleks [220]

Answer: Concurrent programs are the programs that execute at the same point of time. They are simultaneous in nature with other concurrent programs.They are executed with the help of threads  to achieve the concurrency without the issue of scheduling. They are consider long running programs.

The program that has the low execution time compared with all other programs gets executed first.If the case of no progress is seen then another thread is executed.This type of execution gives the non- deterministic situation in which the possibility of leading completion of any particular program cannot be determined.

5 0
3 years ago
Other questions:
  • Wharton professor Jerry Wind "believe[s] that digital networks are the key differentiator, [and] enable new forms of sharing, di
    9·1 answer
  • The ____ is a single user, nonportable computer designed to perform engineering, cad, and software development work.
    9·1 answer
  • COMPUTER SCIENCE HELP!!!!!
    6·1 answer
  • • Describe the steps in detail that the operating system performs to handle interrupts, including ISRs, the stack, and hardware?
    5·1 answer
  • What is the name of the option in most presentation applications with which you can modify slide elements?
    9·2 answers
  • The principal objectives of computer security are to prevent unauthorized users from gaining access to resources, to prevent leg
    11·1 answer
  • You need to buy a cable to connect a desktop PC to a router. Which cable should
    13·1 answer
  • Jeni is using the Label Wizard to solve a problem. What problem was she most likely experiencing?
    13·1 answer
  • Tax preparation software can help prepare and file your taxes by _________.
    7·1 answer
  • Select a software package/electronic device that you know well. It can be from any domain (work related, entertainment, desktop,
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!