16 : C Program to Calculate Surface area of Cube

Check out the complete list of c-programs : C Program List    



To calculate surface area of cube you need to know the side of the cube

Variables :

1. side : (Datatype int) : to represent the side of cube.

2. surface_area_of_cube : (Datatype long) : to store volume of Surface area of cube.





Functions :

printf() : is used to display something on the console/screen. Format specifier %d in printf function is used to display a int variable on screen and %f for float. \n is used to add a newline

scanf() : is used to fetch data inputted by the user on the console/screen using keyboard. %d in scanf is indicates that inputted text is of type int and %f for float.







Formula :

Surface Area of a Cube : 6 x side3


/*
 * 1000+ C programs + tutorials
 *
 *
 * 15_calculate_surface_area_of_cude.c
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include <stdio.h>
//#include  <conio.h>

void main() {

  int side;
  long surface_area_of_cube;

//	clrscr();

	printf(" Program to calculate Surface Area of a Cube :  ");

	printf("\n\n Enter the Side of Cube : ");
	scanf("%d", &side);
    
    
    
    surface_area_of_cube = 6*side*side;


	printf("\n\n Surface area of Cude with side as %d = %ld",side,surface_area_of_cube);

//	getch();



/* Result :

 Program to calculate Surface Area of a Cube :  

 Enter the Side of Cube : 

 Surface area of Cude with side as 3 = 54

*/

}




Using pow(x,y) function :


/*
 * 1000+ C programs + tutorials
 *
 *
 * 15_calculate_surface_area_of_cude.c
 *
 *
 *  Created on: Oct 20, 2014
 *  Author: Code2care.org
 */

#include <stdio.h>
//#include  <conio.h>

void main() {

  int side;
  long surface_area_of_cube;

//	clrscr();

	printf(" Program to calculate Surface Area of a Cube :  ");

	printf("\n\n Enter the Side of Cube : ");
	scanf("%d", &side);
    
    
    //using pow fuction
    surface_area_of_cube = 6*pow(side,2);


	printf("\n\n Surface area of Cude with side as %d = %ld",side,surface_area_of_cube);

//	getch();



/* Result :

 Program to calculate Surface Area of a Cube :  

 Enter the Side of Cube : 

 Surface area of Cude with side as 3 = 54

*/

}








The best way to learn C programming is to practice more and more of programs . Code2care C Programming tutorials provide 1000+ programs in C that you can study and become an expert in the language. Programs are divided into categories depending upon type and complexity.

BSc. IT, BSc. Computer Science, BSc. IT, MSc. IT, MSc. Computer Science, MCA, BTech IT & BTech Engineers may find these programs very useful.