Skip to content

Find Area Of A Cube

Updated: at 02:09 AM

Table of contents

Open Table of contents

Write a program to find area of a cube

Area of cube = 6 × Side^2

Side : 2

Area : 24

C

// Write a C program to find area of a cube

#include<stdio.h>

int main(){
    int side;
    scanf("%d",&side);
    int area=6*side*side;
    printf("Area of the cube: %d",area);
    return 0;
}

C#

// Write a C# program to find area of a cube

using System;
class MainClass {
    public static void Main (string[] args) {
    Console.WriteLine ("Please enter the side : ");
    double side = Convert.ToDouble(Console.ReadLine());
    double cube = 6 * side * side;
    Console.WriteLine("Area of cube : "+cube);
  }
}

C++

// Write a C++ program to find area of a cube

// Programme to find the area of a cube.

#include <bits/stdc++.h>
#define ll long long // for typing ease.
using namespace std;

int main(){
    // Taking input;
    ll length;
    cout<<"Enter the side of the cube: ";
    cin>>length;

    //printing output;
    cout<<"The Surface area of the cube is: "<<6*(length*length)<<endl;

    return 0;
}

/*
Author : Kartikeya Saini
*/

Dart

// Write a Dart program to find area of a cube

import 'dart:io';
void main(){
  print("Enter the side :");
  int side = int.parse(stdin.readLineSync()!);
  int area = 6 * side * side;
  print('Area of cube : $area');
}

F#

// Write a F# program to find area of a cube

let areaOfCube side : int =
  6 * side * side

let area = areaOfCube 2

printfn "Area of cube : %d" area

Go

// Write a Go program to find area of a cube

package main

import "fmt"

func main() {
	var num int
	fmt.Print("Enter the side of a cube to find its area = ")
	fmt.Scanln(&num)
	cube := 6 * num * num
	fmt.Println("\nArea of Cube with side", num, "=", cube)
}

Haskell

-- Write a Haskell program to find area of a cube

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

    let area = 6 * side * side
    putStrLn $ show (area)

Java

// Write a Java program to find area of a cube

import java.util.*;
public class FindAreaofACube{
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int side=sc.nextInt();
        int area=6*side*side;
        System.out.println("Area of the cube: " + area);
    }
}

JavaScript

// Write a JavaScript program to find area of a cube

function areaOfCube() {
  let side = parseFloat(prompt("Enter the length of a side of the cube:"));
  return 6 * side * side;
}

let area = areaOfCube();
console.log("The area of the cube is " + area);

Julia

# Write a Julia program to find area of a cube

print("Enter the side: ")
side = parse(Float64, readline(stdin))
cube = 6 * side * side
println("Surface area of cone: ", cube)

Kotlin

// Write a Kotlin program to find area of a cube

class FindAreaOfACube {
    fun area(side: Int): Int {
        return 6 * side * side
    }
}

Perl

# Write a Perl program to find area of a cube

my $side = <STDIN>;
$area = 6 * $side * $side;
print "$area"

PHP

// Write a PHP program to find area of a cube

<?php
	$x = readline('Enter Cube side: ');

  $x1 = 6* $x * $x;
  echo "Area of Cube: $x1 \n";
?>

Python

# Write a Python program to find area of a cube

# Python program to calculate area of cube

side = input("Enter side of the cube\n")
side = int(side)
area = 6 * side * side

print("Area = ", area)

R

# Write a R program to find area of a cube

side = 2
area = 6* side * side
cat("Area: ", area)

Ruby

# Write a Ruby program to find area of a cube

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

area = 6 * side * side
print "area : #{area}"

Rust

// Write a Rust program to find area of a cube

fn main() {
    let side = 2.0;
    let area = 6.0 * (side * side);

    println!("Area of cube is {0}", area as f32);
}

Scala

// Write a Scala program to find area of a cube

object HelloWorld {
	def main(args: Array[String]): Unit = {
	  val side = scala.io.StdIn.readDouble();
	  val area = 6 * side * side ;
	  println(area);
	}
}

Swift

// Write a Swift program to find area of a cube

import Swift
import Foundation

var side = 2.0

var area = 6 * side * side
print("Area of cube: ", area)

TypeScript

// Write a TypeScript program to find area of a cube

const side = 2;

function area(side: number): number {
  return 6 * side * side;
}

console.log("Side: " + side);
console.log("Area: " + area(side));

Similar programs