Advertisement
sp_Showrav

recursion

Jul 22nd, 2017
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.24 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3. int addnumber(int n);
  4. int main(){
  5.  
  6. int N;
  7. cin>>N;
  8. cout<< addnumber(N);
  9. return 0;
  10. }
  11. int addnumber(int n){
  12.     if(n!=0)
  13.         return n + addnumber(n-1);
  14.     else
  15.         return n;
  16.  
  17.  
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement