C语言笔记:递归法累加

自写函数,递归

#include 
int leijia(int num)
{
	int f;
	if (num==1) f=1;
	else f=leijia(num-1)+num;
	return (f);
}
int main()
{
	int num,result;
	printf("Please input a number:\n");
	scanf("%d",&num);
	result=leijia(num);
	printf("The result is:\n");
	printf("%d\n",result);
	return 0;
}