# WAP in C that uses a function to calculate volume,surface area of a Sphere

The Program in C that uses a function to calculate volume,surface area of a Sphere is given below:

``````#include <stdio.h>
#include <math.h>

void sphere_volume_surface(double diameter, double *volume, double *surface) {
double radius = diameter / 2;
// Function to calculate the volume and surface area of a sphere
*volume = (4.0/3.0) * M_PI * pow(radius, 3);
*surface = 4 * M_PI * pow(radius, 2);
}

int main() {
double diameter, volume, surface;

printf("Enter the diameter of the sphere: ");
scanf("%lf", &diameter);

sphere_volume_surface(diameter, &volume, &surface);
printf("The volume of the sphere is: %lf\n", volume);
printf("The surface area of the sphere is: %lf", surface);

return 0;
}
``````

## Output:

Enter the diameter of the sphere: 7
The volume of the sphere is: 179.594380
The surface area of the sphere is: 153.938040

## Pro-Tips💡

This program defines a function `sphere_volume_surface()` that takes in three parameters: the diameter of the sphere, and two pointers to variables that will hold the calculated volume and surface area.

Inside the function, it calculates the radius of sphere by dividing the diameter by 2.

Then it uses the formulas for the volume and surface area of a sphere to calculate the values and assigns them to the variables pointed to by the pointers.

In the `main()` function, the program prompts the user to enter the diameter of the sphere, and then calls the `sphere_volume_surface()` function to calculate the volume and surface area.

The calculated values are then printed to the console

### Learn C-Sharp ↗

C-sharp covers every topic to learn about C-Sharp thoroughly.

### Learn C Programming ↗

C-Programming covers every topic to learn about C-Sharp thoroughly.

### Learn C++ Programming↗

C++ covers every topic to learn about C-Sharp thoroughly.

Codeauri is Code Learning Hub and Community for every Coder to learn Coding by navigating Structurally from Basic Programming to Front-End Development, Back-End Development to Database, and many more.

## C# Program to Find Sum of Rows & Columns of a Matrix

The Program in C# Program to Find Sum of Rows & Columns of a Matrix is given below: Output: Hello Codeauri Family,enter the number of rows and columns…

## C# Program to Calculate Determinant of Given Matrix

The Program in C# Program to Calculate Determinant of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns of the matrix…

## C# Program to Find Sum of right Diagonals of a Matrix

The Program in C# Program to Find Sum of right Diagonals of a Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns…

## C# Program to Find Transpose of Given Matrix

The Program in C# Program to Find Transpose of Given Matrix is given below: Output: Hello Codeauri Family, enter the number of rows and columns in the matrix:22Enter…

## C# Program for Multiplication of two square Matrices

The Program in C# Program for Multiplication of two square Matrices is given below: Output: Hello Codeauri Family, enter the number of rows/columns in the matrices:2Enter the elements…

## C# Program to Delete Element at Desired position From Array

The Program in C# Program to Delete Element at Desired position From Array is given below: Output: Hello Codeauri Family, enter the number of elements in the array:4Enter…

Your Journey into Code Begins Now: Discover the Wonders of Basic Programming

X