fact2.c

来自「稀疏矩阵、链表、图、队列、二叉树、多叉树、排序、遗传算法等的实现」· C语言 代码 · 共 37 行

C
37
字号
#include <stdlib.h>#include <stdio.h>static unsigned long count;longfact(int x) {	long accumulator = 1;start:	++count;	/* fact(0) is 1, negative numbers don't make sense so we pretend	 * they're 1. */	if (x < 2)		return accumulator;	/* we multiply the accumulator by our top-level x */	accumulator *= x;	/* and trim x by one */	x = x - 1;	goto start;}intmain(void) {	int i;	long f;	for (i = 1; i < 20; ++i) {		count = 0;		f = fact(i);		printf("fact(%02d) gives %ld after %lu iteration%s.\n",			i, f, count, count == 1 ? "" : "s");	}	return 0;}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?