Sponsored Ad

Friday, September 10, 2010

How to Calculate Cube of a Number in C#

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.

How to Calculate Cube of a Number in C#

 

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();           
        }
    }
}

2 comments:

  1. what if Loop will use what is the code?

    ReplyDelete
  2. There is no need to use loop. this is straight forward multiplication.

    ReplyDelete

Sponsored Ad

Website Update

Followers