C# program to take a number as input and calculate the square of that number
Following program shows how to take a number as input and calculate the square of that number.
In this program we get input from user and prints square of that number using following formula
Square of number = input X input
using System;
class MainClass {
public static void Main (string[] args) {
Console.WriteLine("Please enter a number:");
int input = Convert.ToInt32(Console.ReadLine());
int result = input * input;
Console.WriteLine("Squre of " + input + " is: " + result);
}
}
Output:
Please enter a number:
4
Squre of 4 is: 16