Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

How many types of functions are there in c?

1092


What language is windows 1.0 written?

1004


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

2609


What is the size of empty structure in c?

1036


Explain how can type-insensitive macros be created?

963


What are the different types of control structures?

998


main() { printf("hello"); fork(); }

1161


What are register variables? What are the advantage of using register variables?

1143


How can I automatically locate a programs configuration files in the same directory as the executable?

1122


How to check whether string is a palindrome, WITHOUT USING STRING FUNCTIONS?

16637


Write the program that calculates and prints the average of several integers. Assume that the last value read is sentinel 9999.

3655


Explain zero based addressing.

977


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

1200


What is volatile variable in c?

1066


What is c standard library?

1162