Pappu19

Sum of nth series

Dec 8th, 2021 (edited)
302
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<iostream>
  2. using namespace std;
  3.  
  4. int sum(int n)
  5. {
  6.     if(n == 0)
  7.     {
  8.         return 0;
  9.     }
  10.     else
  11.         return n+sum(n-1);
  12. }
  13.  
  14. int main()
  15. {
  16.     int n;
  17.  
  18.     cout<<"Enter Number : "<<"\n";
  19.     cin>>n;
  20.  
  21.     int s = sum(n);
  22.  
  23.     cout<<s;
  24. }
  25.  
RAW Paste Data