sornram9254

Sum_Factorial.cpp

Jul 25th, 2013
102
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 sum(int n) {
  4.     if(n==0)
  5.         return 0;
  6.     else
  7.         return n+sum(n-1);
  8. }
  9. int main()
  10. {
  11.     int putNum;
  12.     cout<<"Input\t:  ";
  13.     cin >> putNum;
  14.     cout<<"Result\t:  "<<sum(putNum)<<endl;
  15.     return 0;
  16. }
Advertisement
Add Comment
Please, Sign In to add comment