C# Programming: How to find pow of given number

February 27, 2014 0 Comments

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

Jacob Lefore

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments: