Created
July 27, 2019 06:32
-
-
Save nevadajames/8f6ed429db26b117dbd4aacff0c1bca0 to your computer and use it in GitHub Desktop.
C program to calculate exponent from command line
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #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