basically returning the value straight as "return pow((n%10),3) + arms(n/=10);" works but not passing it through another variable?
#include <stdio.h>
#include <math.h>
void arms(int n){
int temp;
if (n!=0){
temp = pow((n%10),3) + arms(n/=10);
}
(temp==n)?printf("ARMS"):printf("NO ARMS");
}
int main() {
arms(153);
return 0;
}
arms
is void
which means that it does not return anything, yet you try to use it in your calculation:
temp = pow((n%10),3) + arms(n/=10);
^^^^^^^^^^^^^^
This is not valid. The compiler can't add void
to pow(%n%10,3)
.
A void
function doesn't return anything but you as a programmer can't use it and expect the compiler to do the work for you, which in this case would be to remove the call to arms
:
temp = pow((n%10),3);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.