diff options
author | Tobias Klauser <tklauser@distanz.ch> | 2008-01-27 11:37:44 +0100 |
---|---|---|
committer | Tobias Klauser <tklauser@xenon.tklauser.home> | 2008-01-27 11:37:44 +0100 |
commit | 7e0f021a9aec35fd8e6725e87e3313b101d26f5e (patch) | |
tree | b1cacc4b24393f517aeb4610e9e1021f954307a8 /reference/C/EXAMPLES/exponent.c |
Initial import (2.0.2-6)2.0.2-6
Diffstat (limited to 'reference/C/EXAMPLES/exponent.c')
-rw-r--r-- | reference/C/EXAMPLES/exponent.c | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/reference/C/EXAMPLES/exponent.c b/reference/C/EXAMPLES/exponent.c new file mode 100644 index 0000000..9967d08 --- /dev/null +++ b/reference/C/EXAMPLES/exponent.c @@ -0,0 +1,46 @@ +/************************************************************************** + * + * Purpose: Give the exponent of a number. + * Author: M. J. Leslie + * Date: 05-Apr-94 + * + **************************************************************************/ + +#include <stdio.h> + +int exponent(int); + +main(int argc,char *argv[]) +{ + int user_val; + char *progname; + + progname=argv[0]; + /* have we got one command line + parameter? */ + if (argc != 2) + { + printf("%s syntax is:\n", progname); + printf("\t%s num - where num is the number you ", progname); + printf("require the exponent of.\n"); + exit(); + } + /* y. Put it in a suitable variable */ + user_val = atoi(argv[1]); + /* get and O/P its exponent. */ + printf(" The exponent of %d is %d \n", user_val, exponent(user_val)); +} + +/************************************************************************ + Get the exponent of an integer number. +*************************************************************************/ + +int exponent(int input) +{ + int count, result=1; + /* 'result *= count' means 'result = result * count' + to fortran programmers... */ + for(count=1; count<=input; count++) result *= count; + + return result; +} |