Skip to content

Instantly share code, notes, and snippets.

@i
Created December 17, 2013 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save i/8014008 to your computer and use it in GitHub Desktop.
Save i/8014008 to your computer and use it in GitHub Desktop.
Sexy way to calculate numbers raised to some exponent
#include <stdio.h>
#include <stdlib.h>
int total;
void npowerk(int n, int k) {
int i;
if (k > 0)
for (i = 0; i < n; i++)
npowerk(n, k - 1);
else
total ++;
}
int main(int argc, char **argv) {
total = 0;
npowerk(atoi(argv[1]), atoi(argv[2]));
printf("%d\n", total);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment