C C++ program to find power of number using recursion

C C++ program to find power of number using recursion

If statement और decision making statements के बारे में अधिक जानने के लिए देखें— If statements in C

C Language के बारे में अधिक जानने के लिए देखें—Brief Introduction of C

C-Language में function recursion किसे कहते है और इसकी क्या उपयोगिता है जानने के लिए देखें— Recursion in C

C program to find power of number using recursion

#include<stdio.h>
int power(int,int);
int main()
{
    int num,pow,c=1,res=1;
    printf("Enter number: ");
    scanf("%d",&num);
    printf("Enter power : ");
    scanf("%d",&pow);
    printf("Result = %d",power(num,pow));
    return 0;
}
int power(int num, int pow)
{
    if(pow==0)
        return 1;
    else
        return num*power(num,pow-1);
}

C++ program to find power of number using recursion

#include<iostream>
using namespace std;
int power(int,int);
int main()
{
    int num,pow,c=1,res=1;
    cout<<"Enter number: ";
    cin>>num;
    cout<<"Enter power : ";
    cin>>pow;
    cout<<"Result = "<<power(num,pow);
    return 0;
}
int power(int num, int pow)
{
    if(pow==0)
        return 1;
    else
        return num*power(num,pow-1);
}

Output of C C++ program to find power of number using recursion

C C++ program to find power of number using recursion

Similar recursion based programs in C C++

  1. Series of natural numbers
  2. Table of number
  3. Factorial of number
  4. Fibonacci series
Share it to:

Published by

admin

I am a computer teacher, programmer and web developer