Topic; Function Write a function-‐oriented program that calculates the power value of the input base number and exponent number. Then display the power value. Sample input/output dialogue:
Enter base number: 5 Input data
Enter exponent number: 3 Second input data
Power value: 125 Output
(The computation is 53 = 5 * 5 * 5 = 125)
Note: you can choose any looping statement if needed.
using System;
using System.Collections.Generic;
using System.Globalization;
namespace App
{
class Program
{
static int power(int baseNumber, int exponentNumber)
{
int result=1;
for(int i=1;i<=exponentNumber){
result*=baseNumber;
}
return result;
}
static void Main(string[] args){
Console.Write("Enter base number: ");
int baseNumber = int.Parse(Console.ReadLine());
Console.Write("Enter exponent number: ");
int exponentNumber = int.Parse(Console.ReadLine());
int powerValue = power(baseNumber, exponentNumber);
Console.Write("Power value: {0}", powerValue);
Console.ReadLine();
}
}
}
Comments
Leave a comment