Advertisement
Guest User

ex 3

a guest
May 26th, 2019
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.34 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/3+...+1/n.
  4.  
  5.  
  6. #include <iostream>
  7.  
  8. using namespace std;
  9.  
  10. int main()
  11. {
  12. float n,i,s=0;
  13. cout<<"N=";cin>>n;
  14. for(i=1;i<=n;i++)
  15. {
  16. s=s+1/i;
  17. }
  18. cout<<"Suma este:"<<s;
  19. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement