Created
July 29, 2019 22:36
-
-
Save parzibyte/121c6731bc0d810d6d8266b48a519887 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
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