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
What does the message "automatic aggregate intialization is an ansi feature" mean?
What is the purpose of sprintf() function?
What is main () in c language?
What is the g value paradox?
Why is #define used?
Why is structure padding done in c?
What is the difference between far and near in c?
When I set a float variable to, say, 3.1, why is printf printing it as 3.0999999?
List out few of the applications that make use of Multilinked Structures?
Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?
Why double pointer is used in c?
struct screen_pos{ int row, col } ;move_right(cursor)struct screen_pos *cursor;{ cursor.col++; } /* This statementhas a syntax error */What is the correct statement a) cursor.col = cursor.col + 1; b) col.cursor++; c) *cursor.col++; d) pointer
What are the properties of union in c?
How do I send escape sequences to control a terminal or other device?
Which control loop is recommended if you have to execute set of statements for fixed number of times?