C# Function which prints square of given number.

/* C# Function which prints square of given number. */
using System;
public class Demo
{
    public static int sqr(int a)
    {
        int ans;
        ans = a * a;
        return ans;
    }

    public static void Main(string[] args)
    {
        int a, ans;
        Console.WriteLine("Enter a digit to find square : ");
        a = Convert.ToInt32(Console.ReadLine());
        ans = sqr(a);
        Console.WriteLine("\n\nSquare of {0} : {1}", a, ans);
        Console.ReadLine();
    }
}

Output :
Enter a digit to find square :
5

Square of 5 : 25



Leave a comment