C Program To Calculate Volume Of Cube | C Programs

How to calculate the volume of cube in C. Here we wrote the program in three different ways using pointers, standard, macros. Do check it and also post your opinions on this blog, how could we improve and other things for the users.

Using Standard

1)The value of side of cube will store into the variable “side”.

2)The value will substituted into the formula area=side*side*side.

3)The calculated value will store in to the variable “area”,and displayed using printfunction.

output:

Using Functions

1)The formula for area of cube is a=s*s*s.

2)We are calling the function float area(float s) ,using area(s).area(s) is calling function and

area(float s) is called function.

3)Then function float area(float s) return the calculated value ,and that value will store into variable “s”.

output:

Using Pointers

1)Here *s,*v are pointer variables.

2)We are calling the function using area(&s,&v) by passing addresses of s,v.

3)The function void area(float *s,float *v) calculate the area ,that area value will store into the variable “v”.That v value will be displayed using printf statement.

output:

Using Macros

1)#define  area(s) represents area(s) is symbolic name to the expression (s*s*s)

2)area(s)replaced with that expression given at #define.

output:

Add a Comment

Your email address will not be published. Required fields are marked *