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
Suggesting that there can be 62 seconds in a minute?
How many types of sorting are there in c?
Can a local variable be volatile in c?
What is the difference between call by value and call by reference in c?
An arrangement of information in memory in such a way that it can be easily accessed and processed by a programming language a) string b) data structure c) pointers d) array
application attempts to perform an operation?
How can you increase the size of a dynamically allocated array?
Is c object oriented?
Explain null pointer.
What is the use of bitwise operator?
Explain the use of fflush() function?
Write a program to implement queue.
What is struct node in c?
Write an efficient algo and C code to shuffle a pack of cards.. this one was a feedback process until we came up with one with no extra storage.
What are different types of operators?