Calculating the square of a number is very easy in C#. You just have to multiply two numbers and print the results. Similarly for cube you can just multiply a number 3 times.
Code to Calculate Square of a Number in C#
using System;
using System.Text;
using System.Collections;
using System.Data;
namespace Console_App
{
public class clsFactorial
{
public static void Main()
{
try
{
Console.WriteLine("Enter a number for Square:");
int Number =Convert.ToInt16( Console.ReadLine());
int SquareNumber = Number * Number;
Console.WriteLine("Square of Number {0} is: {1}",Number, SquareNumber );
}
catch(Exception ex)
{
//handle exception here
}
Console.ReadLine();
}
}
}
0 comments:
Post a Comment