c programming of binary addition of two binary numbers
Answer Posted / leon
#include<stdio.h>
#include<conio.h>
int main()
{
long int n1,n2,r=0,sum[50];
int n,i=0;
clrscr();
printf("\n\n Enter First Binary Number: ");
scanf("%ld",&n1);
printf("\n\n Enter Second Binary Number: ");
scanf("%ld",&n2);
while (n1!=0 || n2!=0)
{
sum[i++]=(n1%10+n2%10+r)%2;
r=(n1%10+n2%10+r)/2;
n1=n1/10;
n2=n2/10;
}
if(r!=0)
sum[i++]=r;
printf("\n\n Sum of two binary numbers: ");
for(i=i-1;i>=0;i--)
printf("%d",sum[i]);
getch();
return 0;
}
| Is This Answer Correct ? | 17 Yes | 4 No |
Post New Answer View All Answers
Do array subscripts always start with zero?
1. Write a function to display the sum of two numbers in the following ways: By using (i) pass by value (ii) pass by address a. function with argument and with return value b. function with argument and without return value c. without argument , with return value d. without argument , without return value Note: Use pass by address.
What are disadvantages of C language.
Is there a way to compare two structure variables?
What is indirection in c?
What do you mean by dynamic memory allocation in c? What functions are used?
where are auto variables stored? What are the characteristics of an auto variable?
Can you add pointers together? Why would you?
how to capitalise first letter of each word in a given string?
What is a structure in c language. how to initialise a structure in c?
What is null in c?
Where define directive used?
What are global variables and explain how do you declare them?
Why do we use stdio h and conio h?
Explain bit masking in c?