- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to calculate power of three using C#?
For power of 3, se the power as 3 and apply a recursive code like the following snippet −
if (p!=0) { return (n * power(n, p - 1)); }
Let’s say the number is 5, then the iterations would be −
power(5, 3 - 1)); // 25 power (5,2-1): // 5
The above would return5*25 i.e 125 as shown below −
Example
using System; using System.IO; public class Demo { public static void Main(string[] args) { int n = 5; int p = 3; long res; res = power(n, p); Console.WriteLine(res); } static long power (int n, int p) { if (p!=0) { return (n * power(n, p - 1)); } return 1; } }
Output
125
- Related Articles
- How to calculate fractional power using C#?
- How to calculate the power exponent value using C#?
- How to calculate Power of a number using recursion in C#?
- C++ Program to Calculate Power Using Recursion
- How to calculate power ?
- C++ Program to Calculate Power of a Number
- Java Program to calculate the power using recursion
- Golang Program to Calculate The Power using Recursion
- C program to calculate power of a given number
- Java program to calculate the power of a Given number using recursion
- How to calculate the Size of Folder using C#?
- Power of Three in Python
- Three Different ways to calculate factorial in C#
- How to calculate the length of the string using C#?
- How to calculate transpose of a matrix using C program?

Advertisements