-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherror.c
More file actions
38 lines (29 loc) · 905 Bytes
/
error.c
File metadata and controls
38 lines (29 loc) · 905 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <stdio.h>
#define PI 3.14159f
float calc_area(int radius);
float calc_volume(int radius);
/*A simple function that reads in a radius and prints out the area and volume of a sphere*/
int main(void){
int radius = 0;
printf("Enter a value for the radius: ");
scanf("%d", &radius);
if(radius >= 0){
printf("For a radius of %i the area of the sphere is %.2f and its volume is %.2f \n", radius, calc_area(radius), calc_volume(radius) );
}
else{
printf("You cannot enter a negative number \n");
}
return 0;
}
/* A function which calculates the surface area of a sphere */
float calc_area(int radius){
float sArea;
sArea = 4*PI*(radius*radius);
return sArea;
}
/* A function which calculates the volume of a sphere */
float calc_volume(int radius){
float sVolume;
sVolume = (4.000f/3.000f)*PI*(radius*radius*radius);
return sVolume;
}