মানে হল যখন Power() method টাতে parameters হিসাবে 3 এবং 4 কে পাঠানো হবে তখন output হবে 3^4=81, i.e Power(3,4) should return 81.
using System;
using System.Collections.Generic;
using System.Linq;
namespace MainPrograms
{
public class Program
{
public static void Main(string[] args)
{
// Prompt the user to enter base
Console.WriteLine("Enter your Base");
int Base = Convert.ToInt32(Console.ReadLine());
// Prompt the user to enter exponent
Console.WriteLine("Enter your exponent");
int exponent = Convert.ToInt32(Console.ReadLine());
// Call the power method passing it Base and Exponent
int Result = Power(Base, exponent);
// In System.Math class there is Pow() static method which is
// very similar to the static Power() method we implemented
// double Result = System.Math.Pow(Base, Exponent);
// Print the result
Console.WriteLine("Result={0}",Result);
Console.ReadKey();
}
private static int Power(int Base, int exponent)
{
// Declare a variable to hold the result
int Result = 1;
// Multiply the Base number with itself, for
// exponent number of times
for (int i = 1; i <= exponent; i++)
{
Result *= Base;
}
return Result;
}
}
}
No comments:
Post a Comment