Advertisement
sebasvp2005

Untitled

Apr 17th, 2024
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. #include <iostream>
  2. #include <string>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <bits/stdc++.h>
  6. using namespace std;
  7.  
  8. int factorial(int n){
  9. int res = 1;
  10. for(int i =1 ; i<=n ;i++) res*=i;
  11. return res;
  12. }
  13.  
  14. int getInput(int l, int r){
  15. int temp;
  16. while(!(cin>>temp) || (temp<l | temp>r)){
  17. cout << "Formato invalido, ingrese de nuevo: ";
  18. cin.clear();
  19. cin.ignore(123, '\n');
  20. }
  21. return temp;
  22. }
  23.  
  24. int main(){
  25. int n,x,y;
  26. cout << "ingrese n: ";
  27. n = getInput(2, 20);
  28. cout << "ingrese x: ";
  29. x = getInput(2, 10);
  30. cout << "ingrese y: ";
  31. y = getInput(2, 5);
  32.  
  33. double ans = 0;
  34.  
  35. for(int i=1; i<=n; i++){
  36. double dividendo = (x-y)* factorial(i);
  37. double divisor = pow(x, i) * pow(y, i+1);
  38.  
  39. ans += dividendo / divisor + (pow(y, x+x) * pow(x, y));
  40. }
  41.  
  42. cout << fixed << setprecision(6) << ans << endl;
  43.  
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement