summaryrefslogtreecommitdiff
path: root/reference/C/EXAMPLES/exponent.c
blob: 9967d08a6501c6f2ca51f50a132350eca46ad787 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
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;
}