Message from C, C++ talks

July 2019

— It is a interview question.... Today I went to interview on that they asked me to slove

— Input is 1001 and 1010 binary form

— So fixed input? No interaction with the user? That seems strange

— You could just hardcode the answer 🤷🏻‍♂️

— 

C Program to Find the Sum of two Binary Numbers

This is a C program to Find the Sum of two Binary Numbers.

Problem Description

This program finds the sum of two binary numbers.

Problem Solution

1. Take two binary numbers as input.
2. Add each bits from the two binary numbers separately starting from LSB.
3. The operations may be as follows.
a) (0+0)=0,
b) (1+0)=1,
c) (1+1)=0 and 1 will be remainder.

— /*

 * C Program to Find the Sum of two Binary Numbers

 */

#include <stdio.h>

 

int main()

{

 

long binary1, binary2;

int i = 0, remainder = 0, sum[20];

 

printf("Enter the first binary number: ");

scanf("%ld", &binary1);

printf("Enter the second binary number: ");

scanf("%ld", &binary2);

while (binary1 != 0 || binary2 != 0)

{

sum[i++] =(binary1 % 10 + binary2 % 10 + remainder) % 2;

remainder =(binary1 % 10 + binary2 % 10 + remainder) / 2;

binary1 = binary1 / 10;

binary2 = binary2 / 10;

}

if (remainder != 0)

sum[i++] = remainder;

--i;

printf("Sum of two binary numbers: ");

while (i >= 0)

printf("%d", sum[i--]);

return 0;

}

Message permanent page

— Jesus fuck use pastebin or smth

— So input is not fixed

— Output:   Enter the first binary number: 100000 Enter the second binary number: 101010 Sum of two binary numbers: 1001010

Message permanent page

— Yeah sure why not

— This group never ceases to amaze me ❤️

— /warn Read the rules

— Rose is busy

— Rose fuckkk ya

— Welcome vipul!
Please read the pinned message 🙂