** There are some strange problems with my code. Originally, the array I used to store the results was output one by one and the sample results, but when the numbers in the array were combined into a number, there was 1 * less *
Here is the result of the code running, where ** the single data behind is the value of the res array of the storage result.
After I do res = res + x [i] * pow (16, length-i-1) operation on the res array, why is there a missing one? ? ?
I hope you guys can help! ! !
#include<stdio.h>
#include<string.h>
#include<math.h>
int res[100]={0};
int getwei(int x[],int length)
{
int res=0;
int i;
for(i=0;i<length;i++)
{
printf("##%d\n",x[i]);
res=res+x[i]*pow(16,length-i-1);
}
return res;
}
int get_eight(int x)
{
//int t=0;
int i=0,j=0;
int re=0;
int num=0;
while(x>0)
{
res[i]=x%8;
printf("**%d\n",res[i]);
x/=8;
i++;
}
num=i;
for(j=0;j<num;j++)
{
re=re+res[j]*pow(10,j);
}
/*
res[i]=0;
while(res[j]!=0)
{
printf("**%d\n",res[j]);
re=re+res[j]*pow(10,j);
j++;
}
*/
return re;
}
int main()
{
int N=0;
int i=0,j=0,k=0;
char str[100][1000];
int m=0,n=0;
int cnt=0;
int wei_num[100]={0}; //权位积之和
int re=0;
//int flag=0;
//输入部分
scanf("%d",&N);
getchar();
int six[N][100]; //存放十进制的int数据
int eight[N][100];
int length[N]; //长度
for(i=0;i<N;i++)
{
//printf("%d",i);
gets(str[i]);
}
for(j=0;j<N;j++)
{
k=0;
//对str[j]进行处理成int型
while(str[j][k]!='\0')
{
//printf("*\n");
if(str[j][k]>='0' && str[j][k]<='9')
{
//printf("这里");
six[j][k]=str[j][k]-'0';
}
if(str[j][k]>='A' && str[j][k]<='F')
{
//printf("那里");
six[j][k]=str[j][k]-55; //A~B
//printf("**%d**\n",six[j][k]);
//flag++;
}
k++;
}
length[j]=k;
}
//十进制得出权位积之和
for(i=0;i<N;i++)
{
wei_num[i]=getwei(six[i],length[i]);
}
for(i=0;i<N;i++)
{
re=get_eight(wei_num[i]);
printf("%d\n",re);
}
return 0;
}