Program 5: WAP To Add Two 1 Byte BCD Numbers
Program 5: WAP To Add Two 1 Byte BCD Numbers
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: