Thursday 15 March 2012

how convert decimal number to hexadecimal number with or without floating point

#include<stdio.h>
main()
{
int i=0,j,a[20],m,c[20],g,f;
char b[]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
float n,e;
printf("enter the decimal number with or without fraction:");
scanf("%f",&n);
m=(int)n;
e=n-m;
while(m>0)
{
a[i]=m%16;
m=m/16;
i=i++;
}
for(f=0;f<=6;f++)
{
e=e*16.0;
c[f]=e;
e=e-c[f];
}
printf("hexadecimal equal\n");
for(j=i-1;j>=0;j--)
{
printf("%c",b[a[j]]);
}
printf(".");
for(g=0;g<f;g++)
printf("%c",b[c[g]]);

}

No comments:

Post a Comment