1
Trying to calculate the volume of the sphere returns a strange number like -1.#QNAN0
.
#include<stdio.h>
#include<stdlib.h>
#include <math.h>
float pi = 3.14;
float param(int x){
float vol,y;
y = pow(x,3);
vol = (4*y)/3*pi;
return vol;
}
int main(){
int x, y;
printf("Digite o raio de uma esfera: ");
scanf(" %f", &x);
y = param(x);
printf("\nO volume de uma esfera eh %f \n", y);
system("pause");
return 0;
}
The result and radius is set to integer
int
. Save variables asfloat
, ideal for working with broken numbers:float x, y;
– jefferson