Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created July 29, 2019 22:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/121c6731bc0d810d6d8266b48a519887 to your computer and use it in GitHub Desktop.
Save parzibyte/121c6731bc0d810d6d8266b48a519887 to your computer and use it in GitHub Desktop.
/*
Calcular el volumen de una esfera
a partir de su radio en C
@author parzibyte
Visita: parzibyte.me
*/
#include <stdio.h>// printf y scanf
#include <math.h>// M_PI y pow
#ifndef MPI
#define M_PI 3.14159265358979323846
#endif
double volumenDeEsfera(double radio);
int main() {
double radio;
printf("Introduce el radio de la esfera:\n");
scanf("%lf", &radio);
printf("Volumen si esfera tiene radio de %lf es: %lf", radio,
volumenDeEsfera(radio));
}
double volumenDeEsfera(double radio) {
/*
1: Elevar radio al cubo y eso multiplicarlo por PI
M_PI * pow(radio, 3);
2: Al resultado anterior lo multiplicamos por 4
(4 * (M_PI * pow(radio, 3)))
3: Al resultado anterior lo dividimos entre 3
(4 * (M_PI * pow(radio, 3))) / 3
*/
return (4 * (M_PI * pow(radio, 3))) / 3;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment