主题:help me !
十六进制转化为十进制:
#include<stdio.h>
void main()
{
int change(char s[]);
int flag=1,i=0;
char s[10],c;
printf("please enter onum:\n");
while (c = getchar() != '\0' && i<10 && flag==1)
if(c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F')
s[i++]=c;
else
{
s[i]='\0';
printf(" turn to :%d\n",change(s));
printf("go on or not?('Y'\'N')\n");
c = getchar();
if(c =='N'||c =='n')
flag=0;
else
{
i=0;
printf("please enter onum:\n");
}
}
}
int change(char s[])
{
int n=0,i;
for(i=0;i<10;i++)
{
if(s[i]>='0' && s[i]<='9')
n = n*16+s[i]-'0';
if(s[i]>='a' && s[i]<='f')
n = n*16+s[i]-'a'+10;
if(s[i]>='A' && s[i]<='F')
n = n*16+s[i]-'A'+10;
}
return(n);
}
#include<stdio.h>
void main()
{
int change(char s[]);
int flag=1,i=0;
char s[10],c;
printf("please enter onum:\n");
while (c = getchar() != '\0' && i<10 && flag==1)
if(c>='0' && c<='9' || c>='a' && c<='f' || c>='A' && c<='F')
s[i++]=c;
else
{
s[i]='\0';
printf(" turn to :%d\n",change(s));
printf("go on or not?('Y'\'N')\n");
c = getchar();
if(c =='N'||c =='n')
flag=0;
else
{
i=0;
printf("please enter onum:\n");
}
}
}
int change(char s[])
{
int n=0,i;
for(i=0;i<10;i++)
{
if(s[i]>='0' && s[i]<='9')
n = n*16+s[i]-'0';
if(s[i]>='a' && s[i]<='f')
n = n*16+s[i]-'a'+10;
if(s[i]>='A' && s[i]<='F')
n = n*16+s[i]-'A'+10;
}
return(n);
}