Advertisement
Alx09

Bianca, problema 1

Jan 13th, 2022
1,064
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.25 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4. int suma(int n){
  5.   if (n < 0 )
  6.      return 0;
  7.   return 2 * n +  suma(n - 1);
  8. }
  9. int main()
  10. {
  11.     int n;
  12.     cout << "n= "; cin >> n;
  13.     cout<<"Rezultatul sumei este: " << suma(n);
  14.     return 0;
  15. }
  16.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement