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 page thrashing?
What is the difference between functions abs() and fabs()?
What is define c?
Explain what is the difference between the expression '++a' and 'a++'?
The % symbol has a special use in a printf statement. Explain how would you place this character as part of the output on the screen?
will u please send me the placement papers to my mail???????????????????
By using C language input a date into it and if it is right?
What does dm mean sexually?
What are static variables in c?
What is a stream?
Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.
How many identifiers are there in c?
What language is lisp written in?
How do you redirect a standard stream?
What is the use of in c?