1
Hello! I am doing an exercise where it is necessary to calculate the cubic root of 10 numbers stored in a vector and transfer them from vector A (where the numbers were read) to vector B ( where they will be transformed into the cube of A, but this is done in another function). the problem is that my program is not doing this conversion. I tried to add a third variable C but it did not help The code is this:
#include <stdio.h>
#include <math.h>
#define tam 10
void cubo(int *B);
int main(){
int A[tam], B[tam];
for(int i = 0; i < tam; i++){
scanf("%d", &A[i]);
}
cubo(A);
return 0;
}
void cubo(int *B){
long C[tam];
for(int i = 0; i < tam; i++){
C[i] = sqrt(sqrt(B[i]));
printf("%d\n", B[i]);
}
}
Mathematically I don’t think that the square root of the square root is the cube root of a number. Maybe you can use
pow(B[i], 1.0/3.0)
and print not the parameter but the result of the operation.– anonimo