This program helps the beginners to calculate cube of a given number using C# code. like in simple mathematics you can calculate cube by multiplying the number 3 times. This code is doing same thing.
Code to Calculate Cube 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 Cube:");
int Number =Convert.ToInt16( Console.ReadLine());
int CubeNumber = Number * Number * Number;
Console.WriteLine("Cube of Number {0} is: {1}", Number, CubeNumber);
}
catch(Exception ex)
{
//handle exception here
}
Console.ReadLine();
}
}
}
what if Loop will use what is the code?
ReplyDeleteThere is no need to use loop. this is straight forward multiplication.
ReplyDelete