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
What are the types of operators in c?
how can f be used for both float and double arguments in printf? Are not they different types?
What is the explanation for modular programming?
please give me a VIRTUSA sample palcement papers.... you will only send TECHNICAL SECTION..... that is help for me Advance Thanks........................
What is the difference between array_name and &array_name?
What are the general description for loop statement and available loop types in c?
Why ca not I do something like this?
What is register variable in c language?
How can I use a preprocessorif expression to ?
What is logical error?
Write a code on reverse string and its complexity.
Is it fine to write void main () or main () in c?
What is the use of bit field?
What is an array? What the different types of arrays in c?
How can I run c program?