单点时限: 2.0 sec
内存限制: 256 MB
定义一个函数 $h2i$,将一个字符串表示的 $16$ 进制数转换成一个 $10$ 进制数。
//********** Specification of hex2int **********
unsigned h2i(char s[]);
/* PreCondition:
s is a string consisting of 0~9,A-F or a-f with at most 8 characters
PostCondition:
return a decimal number equivalent to s
Examples: "100" ==> 256 ; "a" ==> 10 ; "0"==> 0
*/
只需按要求写出函数定义,并使用给定的测试程序测试你所定义函数的正确性。
不要改动测试程序。
测试正确后,将测试程序和函数定义一起提交。
/***************************************************************/
/* */
/* DON'T MODIFY main function ANYWAY! */
/* */
/***************************************************************/
#include <stdio.h>
#define N 8
//********** Specification of hex2int **********
unsigned h2i(char s[])
/*
PreCondition:
s is a string consisting of 0~9,A-F or a-f with at most 8 characters
PostCondition:
return a decimal number equivalent to s
Examples: "100"==>256 ; "a"==> 10 ; "0"==> 0
*/
{
//TODO: your function definition
}
/***************************************************************/
int main()
{
char s[N+1];
scanf("%s",s);
//********** hex2int is called here ****************
printf("%u\n",h2i(s));
//**************************************************
return 0;
}
100
256