gpt4 book ai didi

将每个碱基转换为另一个碱基(不起作用)

转载 作者:行者123 更新时间:2023-11-30 21:03:49 24 4
gpt4 key购买 nike

我编写了一个 C 程序,将每个基数转换为另一个基数..但是当我要将 ascii 代码转换为数字时,我遇到了一个问题...请帮忙 :)我认为我的问题是因为我无法将 assci 转换为数字,它说:====> 对“pow”的 undefined reference

#include <stdio.h>
#include <math.h>

int CB, DB;
void base(void)
{
int adad2[100], i=-1,j;
char adad1[100], ch;
long int num1=0, num2=0;
printf("Enter your num: ");
scanf("%c", &ch);

do
{
i++;
scanf("%c", &adad1[i]);
} while(adad1[i]!='\n');

j=i-1;
for(i=j;i>=0;i--)
{ //converts the base to 10.
if(adad1[i]<='9'&& adad1[i]>='0')
{
num1+=((long int)pow((float)CB,(j-i)))*(((int)adad1[i])-48); //converting ascii code to num
}
else if(adad1[i]<='Z'&&adad1[i]>='A')
{
num1+=((long int)pow((float)CB,(j-i)))*(((int)adad1[i])-55);
}
else if(adad1[i]<='z'&&adad1[i]>='a')
{
num1+=((long int)pow((float)CB,(j-i)))*(((int)adad1[i])-87);
}
}

i=0;
while(num1>=DB)
{ //converts the base to b. (START)
adad2[i]=num1%DB;
i++;
num1/=DB;
}

adad2[i]=num1; //converts the base to b. (END)
printf("\nResult: \n");

for(;i>=0;i--)
{ //prints the result.
if(adad2[i]<=9&&adad2[i]>=0){
printf("%d",adad2[i]);
}

else if(adad2[i]>=10&&adad2[i]<=35){
printf("%c",(char)(adad2[i]+55));
}
}
}

void main(void)
{
printf("\nEnter current base: ");
scanf("%d", &CB);

printf("\nEnter desired base: ");
scanf("%d", &DB);

base();

}

最佳答案

当您从编译器收到错误时

 undefined reference to `pow'  

那么说明该库函数没有与你的程序链接。为此,您必须包含包含 pow 定义的 header 。功能。在 GCC 中使用 lm 编译它旗帜。它将包括<math.h>包含库函数定义的头文件 pow

关于将每个碱基转换为另一个碱基(不起作用),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20309782/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com