Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Prodentim Probiotics Specially Designed For The Health Of Your Teeth And Gums

Instant Grammar Checker - Correct all grammar errors and enhance your writing

Teach Your Child To Read

Powerful WordPress hosting for WordPress professionals

Disclosure: My content contains affiliate links.

31,166 questions

40,722 answers

573 users

How to write a recursive function that calculate power in C

Freaking Awesome WordPress Hosting
127 views
asked Aug 1, 2014 by avibootz
edited Feb 26, 2016 by avibootz

1 Answer

0 votes
#include <stdio.h>
 
int power(int x, int y);
 
int main(void)
{
    printf("%d\n", power(2, 3)); // 8
    printf("%d\n", power(2, 4)); // 16
    printf("%d\n", power(3, 2)); // 9
    printf("%d\n", power(3, 3)); // 27
    printf("%d\n", power(5, 4)); // 625
            
    return 0;
}
int power(int x, int y)
{
    if (y == 0)
        return 1;
    return x * power(x, y - 1);
}




answered Aug 1, 2014 by avibootz

Related questions

1 answer 2,302 views
1 answer 795 views
1 answer 130 views
1 answer 99 views
...