12 求1+2+...+n
参考 http://www.cppblog.com/zengwei0771/archive/2012/04/28/173014.html 和 http://blog.csdn.net/shiren_bod/article/details/6703467
代码:
#include<iostream> using namespace std; long add_func(int n,long& sum) { (n>0) && (add_func(n-1,sum)); return (sum+=n); } int main(void) { int n=100; long sum=0; cout<<"1+2+...+100="<<add_func(n,sum)<<endl; }