Answer:
The following program is to calculate the surface area and volume of a sphere(ball) using macro in c language .
#include <math.h> //header file for math functions
#define pi 3.1415 //using macro
#include <stdio.h> //header file for printf() or scanf()
int main() //main function
{
double radius; //radius is a double type variable
float surface_area, vol; //surface_area andvolume is a float type variable
printf("Enter the radius of the sphere : \n"); //printf() is use to print an output
scanf("%lf", &radius); //scanf() is use to take input from the user
surface_area = 4 * pi * pow(radius,2);
vol = (4.0/3) * pi * pow(radius,3);
printf("The Surface area of the sphere is: %.3f", surface_area); // display surface area
printf("\n Volume of the sphere is : %.3f", vol); // display volume
return 0;
}
Output:
Enter radius of the sphere : 4.4
Surface area of sphere is: 243.278
Volume of sphere is : 356.807
Explanation:
Here in this program we include the header file math.h and include the macro pi. after that taking the user input in radius and calculating the surface area and volume of sphere and finally display the result.