Ask Question - Get Answer

1 Ans Write a C program to implement x power n using recursion

Asked by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:47 PM at (Education Tutorials)

Please log in to answer, like and save
0
Save 0

<<< Previous
Log in to Answer Next >>>

Answer(s):

Implementing x power n using recursion :


#include<stdio.h>

#include<math.h>

int power(int x, int n)

{

    if(n)

    {

        return x * power(x, n-1);

    }

    return 1;

}

int main()

{

    int x, n, result;

    scanf("%d%d", &x, &n);

    result=power(x, n);

    printf("%d", result);

    return 0;

}

 

Answered by AL MaMun (4 Golds) Friday, 31 Jul 2020, 04:48 PM

Please log in to Upvote, Downvote and Report
           

Related Q/A:

2 Ans Write a C program for Binary Search algorithm

1 Ans A C program to input and display an Array

1 Ans The general rules for constructing names for variables (unique identifiers)

1 Ans How to Learn HTML - HyperText Markup Language easily? 

1 Ans Write a C program to print Fibonacci number series

1 Ans Write a C Program to check Anagrams of two strings

1 Ans Write a C program to check a perfect number

1 Ans Write a C program to check Bubble sort data structure and algorithm

1 Ans Write a C program to reverse a number

1 Ans Write a C program to implement Insertion sort data structure and algorithm