Sunday, November 5, 2017

Power of a Number in C#

In this article our program will ask the user to give the base and exponent value and then our program will solve the power value. I wrote this program using C# as my programming language.

I am currently accepting programming work kindly contact me in the following email address for further details. Thank you.

My email address are the following jakerpomperada@gmail.com and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental is (034) 4335675.




Sample Program Output


Program Listing


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

namespace ConsoleApplication1
{
    public class Power_Number
    {

        public static int Power(int number, int exponent)
        {
            if (exponent == 0)
                return 1;
            else
                return number * Power(number, exponent - 1);
        }
    
        
        public static void Main()
        {

            int number = 0;
            int exponent = 0; 
            Console.WriteLine("Power of a Number in C# ");
            Console.Write("\n");
            Console.WriteLine("By Mr. Jake R. Pomperada, MAED-IT ");
            Console.Write("\n\n");
  
            Console.Write( "Give Base : " );
            number = Convert.ToInt32( Console.ReadLine() );
            Console.Write( "Give Exponent: " );
            exponent = Convert.ToInt32( Console.ReadLine() );

            Console.Write("\n\n");
            Console.Write("The result ");
            Console.Write("\n\n");
            Console.WriteLine( "{0} ^ {1}= {2} ",number,exponent, Power( number, exponent) );

            Console.Write("\n\n");
            Console.Write("\t Thank You For Using This Software.");
            Console.ReadKey();
        }


     
    }

    
}





No comments:

Post a Comment