Q:

Write a program in C# Sharp to create a function to calculate the result of raising an integer number to another

0

Write a program in C# Sharp to create a function to calculate the result of raising an integer number to another.

Test Data :
Input Base number: 3
Input the Exponent : 2
Expected Output :
So, the number 3 ^ (to the power) 2 = 9

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

using System;
public class funcexer7
{
 public static void Main()
 {
  int n1;
  int exp1;
	  Console.Write("\n\nFunction : To calculate the result of raising an integer number to another :\n");
      Console.Write("--------------------------------------------------------------------------------\n");
	  Console.Write("Input Base number: ");
      n1= Convert.ToInt32(Console.ReadLine());
      Console.Write("Input the Exponent : ");
      exp1= Convert.ToInt32(Console.ReadLine());	  
      Console.WriteLine("So, the number {0} ^ (to the power) {1} = {2} ",n1, exp1, PowerRaising(n1, exp1));
 }
 public static int PowerRaising(int num, int exp)
 {
  int rvalue = 1;
  int i;
  for (i=1;i<=exp;i++)
  rvalue=rvalue*num;
  return rvalue;
 }
} 

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now