C Program to Find Volume and Surface Area of a Cube

In this tutorial, i am going to show you how to find or calculate volume and surface area of Cube with the help of standard formula, function and pointer in c programs.

All C Programs to Find Volume and Surface Area of Cube

  • C Program to Find Volume and Surface Area of Cube using Standard Formula
  • C Program to Find Volume and Surface Area of Cube using Function
  • C Program to Find Volume and Surface Area of Cube using Pointer

C Program to Find Volume and Surface Area of Cube using Standard Formula

#include<stdio.h>
int main()
{
	
	float side,area;
	printf("enter side of cube: ");
	scanf("%f",&side);
	
   
	area=side*side*side;
	printf("Volume and Surface Area of a Cube: %f\n",area);
	return 0;
}

The result of the above c program; as follows:

enter side of cube: 10
Volume and Surface Area of a Cube: 1000.000000

C Program to Find Volume and Surface Area of Cube using Function

#include<stdio.h>
float area(float s)
{
	return (s*s*s);
}
 
int main()
{
 
	float v,s;
	printf("enter side of the cube: ");
	scanf("%f",&s);
	
        s=area(s); 
	printf("Volume and Surface Area of a Cube: %f\n",s);
	return 0;
}

The result of the above c program; as follows:

enter side of the cube: 112
Volume and Surface Area of a Cube: 1404928.000000

C Program to Find Volume and Surface Area of Cube using Pointer

#include<stdio.h>
void area(float *s,float *v)
{
	*v=(*s)*(*s)*(*s);
}
 
 
 
int main()
{
	
	float s,v;
	printf("enter side: ");
	scanf("%f",&s);
	
        area(&s,&v); 
	printf("Volume and Surface Area of a Cube: %f\n",v);
	return 0;
}

The result of the above c program; as follows:

enter side: 15
Volume and Surface Area of a Cube: 3375.000000

More C Programming Tutorials

Leave a Comment