Skip to content

Instantly share code, notes, and snippets.

@nevadajames
Created July 27, 2019 06:32
Show Gist options
  • Select an option

  • Save nevadajames/8f6ed429db26b117dbd4aacff0c1bca0 to your computer and use it in GitHub Desktop.

Select an option

Save nevadajames/8f6ed429db26b117dbd4aacff0c1bca0 to your computer and use it in GitHub Desktop.
C program to calculate exponent from command line
#include <stdio.h>
#include <stdlib.h>
int power(int base, int n){
int p;
for(p = 1; n > 0; n-- ){
p = p * base;
}
return p;
}
int main(int argc, char** argv){
int base = atoi(argv[1]);
int n = atoi(argv[2]);
int result = power(base, n);
printf("\n %u to th %u power = %u\n", base, n, result);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment