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 wrong with this statement? Myname = 'robin';
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
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?
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.?
How do you convert strings to numbers in C?
In which layer of the network datastructure format change is done
Which is the best website to learn c programming?
Do you know the difference between exit() and _exit() function in c?
What are predefined functions in c?
What is function definition in c?
What are control structures? What are the different types?
What is spaghetti programming?
what are the 10 different models of writing an addition program in C language?
Write a program of prime number using recursion.
what will be the output for the following main() { printf("hi" "hello"); }