1
3.4kviews
Write a program using recursive function 'power' to compute $x^n$

power(x, n) = 1 if n = 0

power(x,n) = x if n – 1

power(x,n) = x*power(x, n - 1) otherwise


Mumbai university > FE > SEM 2 > Structured Programming Approach

Marks: 10M

Year: May 2014

1 Answer
1
249views

Algorithm:

Main () Function:

  • Start.
  • Print “Enter values of x and n”.
  • Input x, n.
  • r = CALL power (arguments: x, n)
  • Print r.
  • Stop.

Exponential (parameters: x, n)

  • Start.
  • If n=0, then return 0.
  • Else if n =1, then return x.
  • Else return(x*CALL exponential(arguments: x, n-1))
  • Stop.

Program:

#include …

Create a free account to keep reading this post.

and 2 others joined a min ago.

Please log in to add an answer.