File: intfact.c

package info (click to toggle)
mathomatic 16.0.5-5.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,192 kB
  • sloc: ansic: 22,029; makefile: 340; sh: 319; python: 96; awk: 39
file content (20 lines) | stat: -rw-r--r-- 315 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Factorial function in C for positive integers.
 *
 * Return (arg!).
 * Returns -1 on error.
 */
int
factorial(int arg)
{
	int	result;

	if (arg < 0)
		return -1;
	for (result = 1; result > 0 && arg > 1; arg--) {
		result *= arg;
	}
	if (result <= 0)	/* return -1 on overflow */
		return -1;
	return result;
}