How to use implement a function for long exponentiation in C

1 Answer

0 votes
#include <stdio.h>

unsigned long powLong(const unsigned long base, int exp) {
    unsigned long result = base;

    for (int i = 1; i < exp; ++i)
        result *= base;

    return result;
}

int main() {
    unsigned long x = 5;

    printf("x^18: %lu\n", powLong(x, 19));

    return 0;
}




/*
run:

x^18: 3831533885

*/

 



answered May 7, 2021 by avibootz

Related questions

...