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 is the difference between #include
a value that does not change during program execution a) variabe b) argument c) parameter d) none
Explain what is a stream?
What does the characters “r” and “w” mean when writing programs that will make use of files?
What is a null pointer in c?
What are different storage class specifiers in c?
What is calloc() function?
Explain the difference between exit() and _exit() function?
write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.
What is class and object in c?
How can I find out the size of a file, prior to reading it in?
What is a scope resolution operator in c?
How many keywords are there in c?
What is the package for freshers(Non IIT) in amazon(hyderabad). And what is the same for those who are a contract employee.
Explain what is output redirection?