Advertisement
VEGASo

Lab #3 Ex. 3

Oct 25th, 2022
554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.44 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4.  
  5. using namespace std;
  6.  
  7.  
  8. double sumD(double x, int n)
  9. {
  10.     return n == 1 ? x : x + sumD(x, n - 1);
  11. }
  12.  
  13.  
  14. double sumF(float x, int n)
  15. {
  16.     return n == 1 ? x : x + sumD(x, n - 1);
  17. }
  18.  
  19.  
  20. int main()
  21. {
  22.     setlocale(LC_ALL, "RU");
  23.  
  24.     double xD{ 0.1 };
  25.     float xF{ 0.1f };
  26.  
  27.     cout << setprecision(18) << sumD(xD, 10) << endl;
  28.     cout << setprecision(18) << sumD(xF, 10) << endl;
  29.  
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement