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
What is getche() function?
Explain how can I write functions that take a variable number of arguments?
program to convert a integer to string in c language'
I need previous papers of CSC.......plz help out by posting them.......
What is the difference between constant pointer and constant variable?
Is it fine to write void main () or main () in c?
What is a structure in c language. how to initialise a structure in c?
How can you pass an array to a function by value?
What is operator promotion?
What is 1d array in c?
What are types of structure?
What is an identifier?
how to solve "unable to open stdio.h and conio.h header files in windows 7 by using Dos-box software
#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); }
What does d mean?