Introduce TinyHttp server
[lcapit-junk-code.git] / expo.c
blobd5d741770d058ee2c3f985e2f65e8d8087df2dd1
1 /*
2 * Exponentiation using recursion
3 *
4 * Luiz Fernando N. Capitulino
5 * <lcapitulino@gmail.com>
6 */
7 #include <stdio.h>
8 #include <stdlib.h>
10 double expr(int base, int n)
12 if (!n)
13 return 1;
14 return (base * expr(base, n - 1));
17 int main(int argc, char *argv[])
19 int base, expo;
21 if (argc != 3) {
22 printf("expo < base > < exponent>\n");
23 exit(1);
26 base = atoi(argv[1]);
27 expo = atoi(argv[2]);
29 if (expo < 0) {
30 fprintf(stderr, "error: the exponent must be positive\n");
31 exit(1);
34 printf("%d exp %d = %.1f\n", base, expo, expr(base, expo));
35 return 0;