How to calculate the cube of a number in C#

1 Answer

0 votes
using System;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {

            int n = cube(2);
            Console.WriteLine(n);

            Console.WriteLine(cube(3));

            n = cube(5);
            Console.WriteLine(n);
        }
        static int cube(int n)
        {
            return (int)Math.Pow(n, 3);
        }
    }
}


/*
run:
    
8
27
125

*/

 



answered Dec 4, 2016 by avibootz

Related questions

1 answer 132 views
1 answer 107 views
107 views asked Jul 15, 2021 by avibootz
1 answer 211 views
1 answer 3,565 views
1 answer 102 views
1 answer 141 views
141 views asked Aug 5, 2020 by avibootz
1 answer 162 views
...