82 / 100

Program To Add Binary Number

Hey learner, In this tutorial we are going to program for the sum of Binary Number in C, So if you want to learn then, follow the below code. So lets start the Add Binary Number Program.

Program for sum of binary number in c

In C programming, the Program to add Binary number is so easy, First of all take two binary number in integer, and then use one and one digit from right side by using mod operation. and add them if the sum of binary number is 10, then 1 should be reminder and take that reminder in the second digit sum. And so on.

Sum of two binary number
Sum of two binary number

Program in C

#include<stdio.h>
int main()
{
	int sum[10], binary1,binary2;
	int i=0, rem =0;
	
	printf("Enter the first binary number : ");
	scanf("%ld",&binary1);
	
	printf("Enter the second binary number : ");
	scanf("%ld",&binary2);
	
	while(binary1!=0 || binary2!=0)
	{
		sum[i++] = (binary1%10 + binary2%10 + rem)%2;
		rem = (binary1%10 + binary2%10)/2;
		
		binary1 = binary1/10;
		binary2 = binary2/10; 
	}
	
	if(rem!=0)
		sum[i++] = rem;
	--i;
	printf("The sum of binary Number is : ");
	while(i>=0)
	{
		printf("%d",sum[i]);
		i--;
	}
	printf("\n\n");
	return 0;
	
}

Video Tutorial for adding Binary Number in C

Learn More Python Tutorials

If you have any queries regarding Program Sum of Binary Number In C, then ask in the comment section, I am happy to answer your question. And If You got some benefits from this article then please share it with your friends.

Leave a Comment

Share via
Copy link
Powered by Social Snap