C# Programming: How to find pow of given number

You can easily find power of given number using Pow, which is static method of Math class. Here we take an example with integer number. Also gives II method , which is performed by programming.

Both method include in single program

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            int a = 2, b = 4;   

            

            Console.WriteLine(" The power of given number is {0}",Math.Pow(a, b));
            // Second method
        int result= Fun(2, 6);
        Console.WriteLine(" The power of given number is {0}", result);
            Console.ReadKey();

        }

        private static int Fun(int a, int b)
        {
            if (b >= 1)
            {
                return (a * Fun(a, --b));
            }
            else
                return 1;
        }
      

    }
}

Code generate the following output

C# Programming: How to find pow of given number
C# Programming: How to find pow of given number C# Programming: How to find pow of given number Reviewed by Jacob Lefore on February 27, 2014 Rating: 5

No comments