0% found this document useful (0 votes)
39 views

Program 5: WAP To Add Two 1 Byte BCD Numbers

This program adds two 1 byte BCD numbers. It takes the BCD numbers as input from the user, adds them together and checks if the sum is greater than 9 or 144 to determine if a carry is needed. It then stores the BCD sum in binary array and prints the result in reverse order.

Uploaded by

Kapil Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views

Program 5: WAP To Add Two 1 Byte BCD Numbers

This program adds two 1 byte BCD numbers. It takes the BCD numbers as input from the user, adds them together and checks if the sum is greater than 9 or 144 to determine if a carry is needed. It then stores the BCD sum in binary array and prints the result in reverse order.

Uploaded by

Kapil Gupta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Program 5

WAP to add two 1 byte BCD numbers

Code:
#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,d,i=0,j,ar[20];
printf("Enter first bcd ");
scanf("%x",&a);
printf("\nEnter second bcd ");
scanf("%x",&b);
c=a+b;
if(c%16>9)
{
c=c+6;
}
d=c-(c%16);
if(d>144)
{
c=c+96;
}
while(c)
{
ar[i]=c%2;
i++;

c=c/2;
}
printf("Addition in BCD is : ");
for(j=i-1;j>=0;j--)
{
printf("%d",ar[j]);
}
getch();
}

OUTPUT:

You might also like