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 are the types of operators in c?

616


how can f be used for both float and double arguments in printf? Are not they different types?

612


What is the explanation for modular programming?

689


please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................

1543


What is the difference between array_name and &array_name?

781






What are the general description for loop statement and available loop types in c?

689


Why ca not I do something like this?

591


What is register variable in c language?

609


How can I use a preprocessorif expression to ?

604


What is logical error?

605


Write a code on reverse string and its complexity.

611


Is it fine to write void main () or main () in c?

549


What is the use of bit field?

648


What is an array? What the different types of arrays in c?

662


How can I run c program?

692