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 / kapil singhal

#include<stdio.h>
main()
{
int n1,n2,i=0,kap=0,k=0,j,temp;
int sum[100];

printf("Enter first binary no. : ");
scanf("%d",&n1);

printf("Enter second binary no. : ");
scanf("%d",&n2);

while(n1 !=0 || n2 !=0){
sum[i]=n1%10 +n2%10 + k;
if(sum[i]>1){
sum[i]=sum[i]%2;
k=1;
}
else{
k=0;
}
n1=n1/10;
n2=n2/10;

i++;

}
if(n1==0 && n2==0){
sum[i]=k;

}
for(j=0;j<=i/2;j++){
temp=sum[j];
sum[j]=sum[i-j];
sum[i-j]=temp;
}
printf("Sum is : ");
for(j=0;j<=i;j++){
printf("%d",sum[j]);
}
}

Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are near, far and huge pointers?

1064


Once I have used freopen, how can I get the original stdout (or stdin) back?

1080


Why is struct padding needed?

1097


How old is c programming language?

1021


An instruction which is analysed and acted upon by the processor prior to the compiler going its work a) directive b) constructive c) constant d) absolute mode

1098


What is modifier & how many types of modifiers available in c?

1032


How do you sort filenames in a directory?

1189


What is bubble sort technique in c?

991


What is omp_num_threads?

1092


What are the differences between new and malloc in C?

1160


What is c method?

1007


How can I manipulate strings of multibyte characters?

1115


What is meant by initialization and how we initialize a variable?

1058


Is there a way to jump out of a function or functions?

1111


A program is required to print your biographic information including: Names, gender, student Number, Cell Number, line of study and your residential address.

1725