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 is getche() function?

810


Explain how can I write functions that take a variable number of arguments?

799


program to convert a integer to string in c language'

2191


I need previous papers of CSC.......plz help out by posting them.......

2072


What is the difference between constant pointer and constant variable?

962


Is it fine to write void main () or main () in c?

742


What is a structure in c language. how to initialise a structure in c?

829


How can you pass an array to a function by value?

831


What is operator promotion?

816


What is 1d array in c?

844


What are types of structure?

824


What is an identifier?

810


how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software

3047


#include main() { int *p, *c, i; i = 5; p = (int*) (malloc(sizeof(i))); printf(" %d",*p); *p = 10; printf(" %d %d",i,*p); c = (int*) calloc(2); printf(" %d ",*c); }

835


What does d mean?

783