Getting input from user

We already studied how to print values in console using Console.WriteLine(). Now we going to study how to get input from user using Console.ReadLine(). In the following code example, the user can input a number, which will be stored inside variable num. Then we are printing out its cube value.

CODE

static void Main(string[] args) {
    // Type a number and press enter
    Console.WriteLine("Enter Number : ");

    // Create a int variable and get user and store it in the variable
    int num = Convert.ToInt32(Console.ReadLine());

    // Print cube Value
    Console.WriteLine("Cube Value is " + Math.Pow(num,3)); //Math.Pow(num,3) is the short way of writing num power 3
}


(Click Here, For more exercises)