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
How many types of functions are there in c?
What language is windows 1.0 written?
To print the pattern 1 2 3 4 5 10 17 18 19 6 15 24 25 20 7 14 23 22 21 8 13 12 11 10 9
What is the size of empty structure in c?
Explain how can type-insensitive macros be created?
What are the different types of control structures?
main() { printf("hello"); fork(); }
What are register variables? What are the advantage of using register variables?
How can I automatically locate a programs configuration files in the same directory as the executable?
How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?
Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.
Explain zero based addressing.
The number of measuring units from an arbitarary starting point in a record,area,or control block to some other point a) recording pointer b) offset c) branching d) none
What is volatile variable in c?
What is c standard library?