c programming of binary addition of two binary numbers

Answer Posted / leon

#include<stdio.h>
#include<conio.h>
int main()
{
long int n1,n2,r=0,sum[50];
int n,i=0;
clrscr();
printf("\n\n Enter First Binary Number: ");
scanf("%ld",&n1);
printf("\n\n Enter Second Binary Number: ");
scanf("%ld",&n2);

while (n1!=0 || n2!=0)
{
sum[i++]=(n1%10+n2%10+r)%2;
r=(n1%10+n2%10+r)/2;
n1=n1/10;
n2=n2/10;
}
if(r!=0)
sum[i++]=r;

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

for(i=i-1;i>=0;i--)
printf("%d",sum[i]);

getch();
return 0;
}

Is This Answer Correct ?    17 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is wrong with this statement? Myname = 'robin';

812


hi folks i m approching for h1 b interview on monday 8th of august at montreal and i m having little problem in my approval notice abt my bithdate my employer has made a mistake while applying it is 12th january and istead of that he had done 18 the of january do any body have any solution for that if yes how can i prove my visa officer abt my real birthdate it urgent please let me know guys thaks dipesh patel

1406


What is the right type to use for boolean values in c? Is there a standard type? Should I use #defines or enums for the true and false values?

599


Function which gives a pointer to a binary trees const an integer value at each code, return function of all the nodes in binary tree.?

617


How do you convert strings to numbers in C?

705






In which layer of the network datastructure format change is done

1428


Which is the best website to learn c programming?

576


Do you know the difference between exit() and _exit() function in c?

605


What are predefined functions in c?

559


What is function definition in c?

582


What are control structures? What are the different types?

589


What is spaghetti programming?

664


what are the 10 different models of writing an addition program in C language?

1434


Write a program of prime number using recursion.

613


what will be the output for the following main() { printf("hi" "hello"); }

9307