w3resource
C# Sharp Programming Exercises

C# Sharp Exercises: Function : To calculate the result of raising an integer number to another

C# Sharp Function : Exercise-7 with Solution

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

Pictorial Presentation:

C# Sharp Exercises: Function : To calculate the result of raising an integer number to another

Sample Solution:

C# Sharp Code:

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;
 }
} 

Sample Output:

Function : To calculate the result of raising an integer number to another :                                  
--------------------------------------------------------------------------------                              
Input Base number: 8                                                                                          
Input the Exponent : 2                                                                                        
So, the number 8 ^ (to the power) 2 = 64  

Flowchart :

Flowchart: C# Sharp Exercises - Function : To calculate the result of raising an integer number to another

C# Sharp Code Editor:

Improve this sample solution and post your code through Disqus

Previous: Write a program in C# Sharp to create a function to swap the values of two integer numbers.
Next: Write a program in C# Sharp to create a function to display the n number Fibonacci sequence.

What is the difficulty level of this exercise?



New Content: Composer: Dependency manager for PHP, R Programming