12 求1+2+...+n
生活随笔
收集整理的這篇文章主要介紹了
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; }?
轉載于:https://www.cnblogs.com/buxianghe/p/3203083.html
總結
以上是生活随笔為你收集整理的12 求1+2+...+n的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 饭卡(HDOJ2546)
- 下一篇: Power of Cryptograph