///
/// 计算小于某整数的加法、乘法
///
/// 为真是加,假为乘
/// 最大数
///
public double compute(bool Ctype, int endNum)
{
double tempNum = 0;
if (endNum-1 > 0)
compute(Ctype, endNum-1);
if (Ctype)
{
return tempNum + endNum;
}
else
{
if (tempNum = 0)
tempNum = 1;
return tempNum * endNum;
}
}
int sum(int n)
{
if(n==1)
return 1;//出口
return sum(n-1)+n;
}
main()
{
int n=100;
printf("%d",sum(n));
}
#include "stdio.h"
int sum(int num)
{
if(num == 1)
return 1;
else
return sum(num-1)+num;
}
main()
{
int num = 100;
printf("答案为:%d\n",sum(100));
}
书本问题....