Skip to content

Find Surface Area Of A Sphere

Updated: at 02:09 AM

Table of contents

Open Table of contents

Write a program to find surface area of a sphere

Surface area of sphere = 4 × π × Radius^2

Radius : 2

Surface area : 50.26548245743669

C

// Write a C program to find surface area of a sphere

#include <stdio.h>

int main()
{
    int radius;
    long double surfaceArea;
    const long double PI = 3.14159265358979;

    printf("Enter radius    :   ");
    scanf("%i", &radius);

    surfaceArea = 4 * PI * radius * radius;

    printf("Surface area of sphere  :   %.14Lf", surfaceArea);

    return 0;
}

C#

// Write a C# program to find surface area of a sphere

using System;
class MainClass {
    public static void Main (string[] args) {
    Console.WriteLine ("Please enter the radius : ");
    double radius = Convert.ToDouble(Console.ReadLine());
    double sphere = 4 * 3.14 * radius * radius;
    Console.WriteLine("Surface area of sphere :"+sphere);
  }
}

C++

// Write a C++ program to find surface area of a sphere

#include <iostream>
#include <bits/stdc++.h>
#define pi 3.141592653589793238
using namespace std;

int main()
{
    int r;cin>>r;
    cout<<fixed<<setprecision(10)<<(4*pi*r*r)<<'\n';
    return 0;
}

Dart

// Write a Dart program to find surface area of a sphere

import 'dart:io';
void main(){
  print("Enter the radius :");
  int radius = int.parse(stdin.readLineSync()!);
  double area = 4.0 * 3.14 * radius * radius;
  print('Surface area of sphere : $area');
}

F#

// Write a F# program to find surface area of a sphere

let surfaceAreafOfSphere radius : float =
  4.0 * 3.14 * radius * radius

let area = surfaceAreafOfSphere 2.0

printfn "Surface area of sphere : %f" area

Go

// Write a Go program to find surface area of a sphere

package main

import (
	"fmt"
	"math"
)

func sphere_surface_area(radius float64) {
	surface_area := 4 * math.Pi * math.Pow(radius, 2)

	fmt.Printf("Radius: %f\nSurface Area: %f", radius, surface_area)

}

func main() {
	var number float64
	fmt.Scanln(&number)
	sphere_surface_area(number)
}

Haskell

-- Write a Haskell program to find surface area of a sphere

main :: IO ()
main = do
    putStrLn "Enter side: "
    input1 <- getLine
    let radius = read input1 :: Float

    let surfaceArea = 4 * pi * radius * radius
    putStrLn $ show (surfaceArea)

Java

// Write a Java program to find surface area of a sphere

import java.util.*;
class findSurfaceAreaOfSphere
{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.print("Enter radius of the sphere: ");
        double r = sc.nextDouble();
        System.out.println("Surface Area of the Sphere with radius " + r + ": " + 4*Math.PI*r*r);
    }
}

JavaScript

// Write a JavaScript program to find surface area of a sphere

function surfaceAreaOfSphere(radius) {
  let area = 4 * Math.PI * Math.pow(radius, 2);
  console.log("The area is: ", area);
}
surfaceAreaOfSphere(2);

Julia

# Write a Julia program to find surface area of a sphere

print("Enter the radius: ")
radius = parse(Float64, readline(stdin))
area =  4 * 3.14 * radius * radius
println("Surface area of sphere: ", area)

Kotlin

// Write a Kotlin program to find surface area of a sphere

import java.util.Scanner
import kotlin.math.pow
import kotlin.math.PI

fun main(args: Array<String>) {

    //Input Stream
    val scanner = Scanner(System.`in`)

    //Input Radius
    print("Enter Radius of Sphere : ")
    val radius = scanner.nextDouble()

    //surface Area of Sphere
    val sphereSurfaceArea = 4*PI*radius.pow(2.0)

    //Print Surface Area
    println("Surface Area of Sphere on radius $radius is :$sphereSurfaceArea")
}

Perl

# Write a Perl program to find surface area of a sphere

#!/usr/bin/perl
use warnings;
use strict;
print "Enter the radius : ";
my $radius = <STDIN>;
my $area = 4 * 3.14  * $radius * $radius ;
print "Surface area of sphere : ".$area, "\n";

PHP

// Write a PHP program to find surface area of a sphere

<?php
	$x = readline('Enter sphere radius: ');

  $x1 = 4 * pi() * $x * $x;
  echo "Surface area of sphere: $x1 \n";
?>

Python

# Write a Python program to find surface area of a sphere

import math


def surfaceAreaOfSphere(radius):
    area = 4 * math.pi * math.pow(radius, 2)
    print("The area is: ", area)


surfaceAreaOfSphere(2)

R

# Write a R program to find surface area of a sphere

radius = 2
surfaceArea = 4 * pi * radius * radius
cat("surfaceArea: ", surfaceArea)

Ruby

# Write a Ruby program to find surface area of a sphere

pi = Math::PI

print "Enter radius : \n"
radius = gets.chomp.to_i

surfaceArea = 4 * pi * radius * radius
print "surface area : #{surfaceArea}"

Rust

// Write a Rust program to find surface area of a sphere

fn main() {
  let radius = 2.0;
  let surfaceArea = 4.0 * 3.14 * radius * radius;

  println!("Surface area of sphere is {0}", surfaceArea as f32);
}

Scala

// Write a Scala program to find surface area of a sphere

object HelloWorld {
	def main(args: Array[String]): Unit = {
	  val Pi = java.lang.Math.PI;
	  val radius = scala.io.StdIn.readDouble();
	  val surfaceArea = 4 * Pi * radius * radius;
	  println("Surface area of the sphere: " + surfaceArea);
	}
}

Swift

// Write a Swift program to find surface area of a sphere

import Swift
import Foundation

var radius = 2.0

var surfaceArea = 4.0 * M_PI * radius * radius
print("Surface area of sphere: ", surfaceArea)

TypeScript

// Write a TypeScript program to find surface area of a sphere

function findSurfaceAreaOfSphere(radius: number) {
  return 4 * Math.PI * Math.pow(radius, 2);
}

console.log(findSurfaceAreaOfSphere(2));

Similar programs