17 : C Program to Calculate Surface area of Sphere

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



Variables :

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

2. PI : (Datatype float) : static variable to represent constant PI value upto 3 decimal places i.e 3.142

2. surface_area_of_sphere : (Datatype long) : to store volume of Surface area of Sphere.





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, %f for float and %ld for long. \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, %f for float and %ld for long.







Formula :

Surface Area of a Sphere : 4 x π x r2


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

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

void main() {

  int radius;
  float PI = 3.142;
  float surface_area_of_sphere;

//	clrscr();

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

	printf("\n\n Enter the Radius of Sphere : ");
	scanf("%d", &radius);
    
    
    
    surface_area_of_sphere = 4*PI*radius*radius;


	printf("\n\n Surface area of Sphere with side as %d = %lf",radius,surface_area_of_sphere);

//	getch();


}




Using pow(x,y) function :


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

void main() {

  int radius;
  float PI = 3.142;
  float surface_area_of_sphere;

//	clrscr();

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

	printf("\n\n Enter the Radius of Sphere : ");
	scanf("%d", &radius);
    
    
    
    surface_area_of_sphere = 4*PI*pow(radius,2);


	printf("\n\n Surface area of Sphere with side as %d = %lf",radius,surface_area_of_sphere);

//	getch();


}










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.