Hi
I have been trying to convert hexadecimal to decimal value just i need to get 5 input hex values and store it in an array and convert them to decimal values, as i compiled i am getting error as "Time limit exceeded".And i tried this on turbo c ,am getting error as "character constant must be one or two characters long".
Code:
#include <stdio.h>
#include<math.h>
#include<string.h>
int main(void) {
int i,j,num,len,counter=0;
long int sum=0; //value can cross range of int
char hex[100]={'1ED7','1ED8','1ED6','1ED5','1ED6'};
//conversion to dec
len=strlen(hex);
printf("%d",len);
for(i=0;i<5;i++)
{
for(i=len-1;i>=0;i--)
{
if(hex[i]>='0'&&hex[i]<='9')
num=hex[i]-'0'; //the character is number in between 0 to 9
else
{
if(hex[i]>='A'&&hex[i]<='F')
num=hex[i]-55; //the character is either a,b,c,d,e or f
else
{
printf("The Entered number is not hexadecimal number");
// getch();// If the character is beyond 'f'
return 1;
}
}
sum=sum+pow(16,counter)*num; //according to formula given by the link
counter++;
}
}
printf("Hexadecimal conversion of %s to decimal is %ld",hex,sum);
return 0;
}
//conversion to weight
// }
// return 0;
//}*/
pls help?!