In C write a function which will take the length of the side

In C, write a function which will take the length of the side of a cube and return the volume and surface area of the cube. Note: since you need to return more than one value from the function, you will need to use pointers.

Solution

#include <stdio.h>
#include <stdlib.h>

/*Volume_Surface_function function definition where volume and surface as pointer variable */
void Volume_Surface_function(double side_length, double *volume, double *surface)
{
/* cube volume formula is V=a^3 where a is side length of cube */
*volume= side_length*side_length*side_length;

/* Cube surface formula is A=6a^2 where a is side length of cube*/
*surface= 6*side_length*side_length;


}

int main()
{
/*declare length variable as double*/
double length;

/*declare volume variable as double*/
double volume;

/*declare surface variable as double*/
double surface;

printf(\"Enter length of the side of a cube : \");

/* read length of the side of a cube from user */
scanf(\"%lf\", &length);
/*calling Volume_Surface_function function*/
Volume_Surface_function(length, &volume, &surface);

printf(\"\ volume of cube is :%.2lf \", volume);
printf(\"\ Surface of cube is :%.2lf\",surface);
printf(\"\ \");
return 0;
}// end of main

------------------------------------------------------------------------------------------------------

output sample:1

Enter length of the side of a cube : 12.5

volume of cube is :1953.13
Surface of cube is :937.50

output sample 2:-

Enter length of the side of a cube : 6

volume of cube is :216.00
Surface of cube is :216.00

output sample 3:-

Enter length of the side of a cube : 3.50

volume of cube is :42.88
Surface of cube is :73.50

---------------------------------------------------------------------------------------------

If you have any query, please feel free to ask

Thanks a lot

In C, write a function which will take the length of the side of a cube and return the volume and surface area of the cube. Note: since you need to return more
In C, write a function which will take the length of the side of a cube and return the volume and surface area of the cube. Note: since you need to return more

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site