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
Can we declare variable anywhere in c?
Explain the difference between strcpy() and memcpy() function?
How can I open files mentioned on the command line, and parse option flags?
What is a void pointer in c?
Tell me what is the purpose of 'register' keyword in c language?
Explain how can I write functions that take a variable number of arguments?
I need a help with a program: Write a C program that uses data input in determining the whole of points A and a whole of circles B. Find two points in A so that the line which passes through them, cut through the maximum number of circles.
What is the size of structure pointer in c?
Explain what is wrong in this statement?
What is a good way to implement complex numbers in c?
What is operator precedence?
Which control loop is recommended if you have to execute set of statements for fixed number of times?
Is there any algorithm to search a string in link list in the minimum time?(please do not suggest the usual method of traversing the link list)
What is a keyword?
Can a variable be both const and volatile?