您的位置:首页 > 其它

求1+2+…+n, 要求不能使用乘除法、for、while、if、else、switch、case等关键字 以及条件判断语句(A?B:C)

2016-05-11 14:28 309 查看
求1+2+…+n,

要求不能使用乘除法、for、while、if、else、switch、case等关键字

以及条件判断语句(A?B:C)

#include <stdio.h>
int sum(int n)
{
int tmp = 0;
(n) && (tmp = sum(n-1));
return n + tmp;
}
int main()
{
printf("%d\n", sum(100));
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: