1
0
mirror of https://github.com/krislamo/knrc.git synced 2024-11-10 00:30:35 +00:00

Function example

This commit is contained in:
Kris Lamoureux 2021-11-23 00:31:57 -05:00
parent f232d42ece
commit 984c019e14
Signed by: kris
GPG Key ID: 3EDA9C3441EDA925

24
13-functions.c Normal file
View File

@ -0,0 +1,24 @@
#include <stdio.h>
int power(int m, int n);
/* test power function */
int main()
{
int i;
for (i = 0; i < 10; ++i)
printf("%d %d %d\n", i, power(2,i), power(-3,i));
return 0;
}
/* power: raise base to n-th power; n >= 0 */
int power(int base, int n)
{
int i, p;
p = 1;
for (i = 1; i <= n; ++i)
p = p * base;
return p;
}