#include <stdio.h>
#include <string.h>
#include <math.h>
int main( )
{
char hex1[100], hex2[100];
int p = 0,q=0;
int decimal1 = 0, decimal2 = 0;
int r, i, j, sum=0;
long decimalnum, quotient, rem;
int ii, jj = 0;
char hex3[100];
printf("Enetr first Hexadecimal: ");
scanf("%s", hex1);
printf("Enetr second Hexadecimal: ");
scanf("%s", hex2);
for(i=strlen(hex1)-1;i>=0;--i)
{
if(hex1[i]>='0' && hex1[i]<='9')
{
r=hex1[i]-'0';
}
else
{
r=hex1[i]-'A'+10;
}
decimal1 = decimal1 +r*pow(16,p);
++p;
}
for(j=strlen(hex2)-1;j>=0;--j)
{
if(hex2[j]>='0' && hex2[j]<='9')
{
r=hex2[j]-'0';
}
else
{
r=hex2[j]-'A'+10;
}
decimal2 = decimal2 +r*pow(16,q);
++q;
}
sum = decimal1 + decimal2;
quotient = sum;
//printf("\n Quotient is: %ld", quotient);
while(quotient != 0)
{
rem = quotient % 16;
if(rem < 10)
{
hex3[jj++] = 48 + rem;
}
else
{
hex3[jj++] = 55 + rem;
}
quotient = quotient/16;
}
jj--;
printf("Sum of two hexadecimal number is ");
for(ii=jj; ii>=0; ii--)
{
printf("%c", hex3[ii]);
}
return 0;
}