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:
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 :
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?
Test your Programming skills with w3resource's quiz.
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework