无法在 for 循环中的 pow 函数上输出答案
can't output answer at pow function in for loop
练习是"输入号A,B和A数字列表c。" a"表示列表C的基础," B"表示将列表C转到基于" B"的数字列表。示例:a = 2,b = 3,c = 10110答案是" 211"
这是我的程序:
#include <iostream>
#include <cstring>
#include <cmath>
#include <cstdlib>
using namespace std;
int main() {
int a,b;
int account, d, size, sum = 0;
char *c, *w;
cout<<"Input two stander a b first, them input a based listed"<<endl;
cin>>a>>b;
cin.ignore();
cin.getline (c,64);
size = strlen(c);
d = atoi(c);
for(int i = 0; i<size; i++){
account = (d%a)*pow(a,i);
sum+=account;
d = (d/a);
}
w = itoa(sum, w, b);
cout<<"the list after transfer: "<<w<<endl;
return 0;
}
我的程序可以通过编译器出现,但是我的计算机无法掩盖数据。我焦急地不知道我的程序在哪里错了。我认为这可能是for循环的功能。有人可以帮我吗?
我复制了您的代码并进行了两个更改:而不是char *c, *w; -> char C [256],W [256];(我的编译器抛出了例外,在这里不喜欢 *C(
而不是w = itoa(sum,w,b(; -> _itoa_s(sum,w,b(;
我使用2 3 101对其进行了测试,并获得了"转移12后列表"。希望这项工作。
但是,仍然有警告"从双重转换到int",应将其视为错误。
相关文章:
- 在 while 循环中使用 pow() 函数 C++
- C++ 中 pow() 函数的输出没有给出准确的答案
- 无法在 for 循环中的 pow 函数上输出答案
- 使用POW()产生不正确值的立方函数
- CMake 无法检测 gcc 内置函数,如 sqrt、pow、exp 等
- 如何在while内部执行pow函数?C++
- POW函数为什么返回意外值
- 如何将POW函数矢量化(具有负碱基)
- C/C 中POW()函数的实现是否随平台或编译器而变化
- C++ 数学库 pow() 函数的时间复杂度
- 为什么math.h的pow函数返回无穷大的值
- C++将pow函数的双结果强制转换为整数
- pow()函数在没有任何数学库的情况下工作
- 编译器决定调用函数“POW”,而不是在编译时对其求值.为什么?
- 仅使用加法的pow函数
- 在不使用函数 pow 的情况下计算表达式的总和
- C 中的 pow() 函数给我带来了错误的结果
- Pow 函数 C++ 错误
- 在Windows上为Matlab构建libspline - 对重载函数'pow'的模糊调用
- 对重载函数'pow'的不明确调用