各位高手速度帮小弟个忙????做个题C++谢谢啦~

来源:百度知道 编辑:UC知道 时间:2024/05/27 19:51:50
int n2dec (int n, int m)
{
int remain,result,count;
result = count = 0;
while(m > 0)
{
remain = m % 10;
m = m / 10;
result += remain * (power(n,count++));
}
return result;
}

是关于进制转换的吧?
不应该是power哈,应该是pow哈,其中头文件是math.h

看下我的例子:
#include "iostream.h"
#include "math.h"
int n2dec (int n, int m)
{
int remain,result,count;
result = count = 0;
while(m > 0)
{
remain = m % 10;
m = m / 10;
result += remain * (pow(n,count++));
}
return result;
}
void main()
{
int m,n;
cout<<"请输入进制n:";
cin>>n;
cout<<"请输入进制为n的数m:";
cin>>m;
cout<<"转换后的十进制数是: ";
cout<<n2dec(n,m)<<endl<<endl;
}