Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- #include <algorithm>
- #include <math.h>
- #include <bits/stdc++.h>
- using namespace std;
- int factorial(int n){
- int res = 1;
- for(int i =1 ; i<=n ;i++) res*=i;
- return res;
- }
- int getInput(int l, int r){
- int temp;
- while(!(cin>>temp) || (temp<l | temp>r)){
- cout << "Formato invalido, ingrese de nuevo: ";
- cin.clear();
- cin.ignore(123, '\n');
- }
- return temp;
- }
- int main(){
- int n,x,y;
- cout << "ingrese n: ";
- n = getInput(2, 20);
- cout << "ingrese x: ";
- x = getInput(2, 10);
- cout << "ingrese y: ";
- y = getInput(2, 5);
- double ans = 0;
- for(int i=1; i<=n; i++){
- double dividendo = (x-y)* factorial(i);
- double divisor = pow(x, i) * pow(y, i+1);
- ans += dividendo / divisor + (pow(y, x+x) * pow(x, y));
- }
- cout << fixed << setprecision(6) << ans << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement