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 are the string functions? List some string functions available in c.
Where static variables are stored in memory in c?
What are enumerated types?
List the difference between a 'copy constructor' and a 'assignment operator' in C?
What is the purpose of realloc()?
Why is c called a structured programming language?
What does the format %10.2 mean when included in a printf statement?
What are multidimensional arrays?
Why malloc is faster than calloc?
What is a keyword?
What is self-referential structure in c programming?
Explain the difference between ++u and u++?
What is typedf?
What are control structures? What are the different types?
Write a program to find the biggest number of three numbers in c?