Users Online

· Guests Online: 112

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C Program to find Power of a Number using Recursion

The following C program, using recursion, finds the power of a number. The power of a number is the number multiplied to itself for the number of times it has been raised to Eg: 7^3 is 343
Here is the source code of the C program to find an element in a linked list. The C Program is successfully compiled and run on a Linux system. The program output is also shown below.

/*
* C Program to find Power of a Number using Recursion
*/
#include <stdio.h>

long power (int, int);

int main()
{
int pow, num;
long result;

printf("Enter a number: ");
scanf("%d", &num);
printf("Enter it's power: ");
scanf("%d", &pow);
result = power(num, pow);
printf("%d^%d is %ld", num, pow, result);
return 0;
}

long power (int num, int pow)
{
if (pow)
{
return (num * power(num, pow - 1));
}
return 1;
}


$ cc pgm30.c
$ a.out
Enter a number: 456
Enter it's power: 3
456^3 is 94818816

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 1.03 seconds
10,836,144 unique visits