Hello Friends,

I have to convert Decimal to Hexadecimal,
I Used this code for it.
But the problem that i am facing is if i enter Decimal=42
It shows Hexadecimal =A.

But it should show Hexadecimal=4A.

What should be done then...??'

CODE :

Code:
int n,r[10],i;
clrscr();
printf("Enter the decimal number\n");
scanf("%d",&n);
for(i=0;i<n;i++)
{
r[i]=n1%16;
n=n/16;
}
i--;
for(i=n;i>=0;i--)
{
if(r[i]==10)
printf("A");
else if(r[i]==11)
printf("B");
else if(r[i]==12)
printf("C");
else if(r[i]==13)
printf("D");
else if(r[i]==14)
printf("E");
else if(r[i]==15)
printf("F");
else
printf("%d",r[i]);
}
printf("\n");
Thank you..

Last edited by shabbir; 17Mar2009 at 18:58.. Reason: Code blocks