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 the use of bitwise operator?
which of the following statement is wrong a) mes=123.56; b) con='T'*'A'; c) this='T'*20; d) 3+a=b;
What do mean by network ?
Simplify the program segment if X = B then C ← true else C ← false
In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?
in multiple branching construct "default" case is a) optional b) compulsarily c) it is not include in this construct d) none of the above
Explain what is a stream?
write a c program to find the sum of five entered numbers using an array named number
What are terms in math?
a program that can input number of records and can view it again the record
What is c variable?
What is pass by reference in functions?
Does free set pointer to null?
This is a variation of the call_me function in the previous question:call_me (myvar)int *myvar;{ *myvar += 5; }The correct way to call this function from main() will be a) call_me(myvar) b) call_me(*myvar) c) call_me(&myvar) d) expanded memory
How is a macro different from a function?