0% found this document useful (0 votes)
60 views2 pages

C Program For Multiplication of Two Binary Numbers Roll No:55 Batch:P3 Sub:Coa

This C program multiplies two binary numbers by repeatedly multiplying the first number by the place value of the second number's digits and adding the results. It takes two binary numbers as input, multiplies the first number by powers of two corresponding to the place value of each digit in the second number if that digit is a 1. It calls a binary addition function to add the results. The program then prints out the product of the two binary numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views2 pages

C Program For Multiplication of Two Binary Numbers Roll No:55 Batch:P3 Sub:Coa

This C program multiplies two binary numbers by repeatedly multiplying the first number by the place value of the second number's digits and adding the results. It takes two binary numbers as input, multiplies the first number by powers of two corresponding to the place value of each digit in the second number if that digit is a 1. It calls a binary addition function to add the results. The program then prints out the product of the two binary numbers.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

C PROGRAM FOR MULTIPLICATION OF TWO BINARY NUMBERS

ROLL NO:55
BATCH:P3
SUB:COA
#include<stdio.h>
#include<conio.h>
long int binaryAddition(long int,long
int);
void main()
{
long int binary1,binary2,multiply=0;
long int digit,factor=1;
clrscr();
printf("\n\n\nEnter any first binary
number: ");
scanf("%ld",&binary1);
printf("\n\n\nEnter any second binary
number: ");
scanf("%ld",&binary2);
while(binary2!=0)
{
digit = binary2 %10;
if(digit ==1)
{
binary1=binary1*factor;
multiply =
binaryAddition(binary1,multiply);
}
else
binary1=binary1*factor;
binary2 = binary2/10;
factor = 10;

}
printf("\n\n\nProduct of two binary
numbers: %ld",multiply);
getch();
}
long int binaryAddition(long int
binary1,long int binary2)
{
long int i=0,remainder = 0,sum[20];
long int binarySum=0;
while(binary1!=0||binary2!=0){
sum[i++] = (binary1 %10 + binary2
%10 + remainder ) % 2;
remainder = (binary1 %10 + binary2
%10 + remainder ) / 2;
binary1 = binary1/10;
binary2 = binary2/10;
}
if(remainder!=0)
sum[i++] = remainder;
--i;
while(i>=0)
binarySum = binarySum*10 +
sum[i--];
return binarySum;
}

OUTPUT:

You might also like