-1

当我运行它时,这根本没有返回任何答案。我不太明白为什么。基本上我需要将给定数字的每个数字乘以它的基数,提升到等于位数的程度。每次运行时功率都会下降。或者它应该,无论如何。它没有。

int num, sum, base;
sum = 0;
cout << "num";
cin >> num;
cout << "base";
cin >> base;

int power = 0;

while (num > 0)
{
    power++;
    num = num/10;
}
return power;
sum = 0 ;
while (num > 0);
{
    sum = (num%10)*(pow(base, power));
    num = num/10;
    power--;


}
sum += sum;

cout << sum;
4

1 回答 1

3

Looking at your code, it looks like you have a rogue return statement in the middle of your function. At least I'm assuming its a function as you don't have a proper function definition in your code.

Remove it and try again!

return power; <-- right here your function will return and no code underneath will be executed
sum = 0 ;
while (num > 0);
{
    sum = (num%10)*(pow(base, power));
    num = num/10;
    power--;
}
sum += sum;

cout << sum;
于 2013-06-27T21:20:11.933 回答