Advertisement
Guest User

ex2

a guest
May 26th, 2019
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. Scrieți un program C++ care citește de la tastatură un număr natural nenul n cu cel mult 3 cifre și calculează suma:
  2.  
  3. S=1/(1*2)+1/(2*3)+1/(3*4)+...+1/(n*(n+1))
  4.  
  5. #include <iostream>
  6.  
  7.  
  8. using namespace std;
  9.  
  10. int main(){
  11.  
  12. int n, i;
  13. float s=0;
  14. cout<<"Introdu numarul:"; cin>>n;
  15. for(i=1; i<=n; i++)
  16. {
  17. s=(float)1/(i*(i+1))+s;;
  18. }
  19. cout<<"Suma este egala cu:"<<s;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement