# Answer to Question #28102 in C++ for Wedd

Question #28102

write a program in C++ for the function a(n)=((2n+1)/(2n!)^2)

Expert's answer

#include <iostream>

using namespace std;

long double calc(int n) {

long double res = (2*n + 1) / 4.0;

for (int i = 2; i <= n; i++)

& res /= i*i;

return res;

}

int main() {

cout << "Input n: ";

int n;

cin >> n;

cout << "(2n+1)/(2n!)^2 = " << calc(n) << endl;

}

using namespace std;

long double calc(int n) {

long double res = (2*n + 1) / 4.0;

for (int i = 2; i <= n; i++)

& res /= i*i;

return res;

}

int main() {

cout << "Input n: ";

int n;

cin >> n;

cout << "(2n+1)/(2n!)^2 = " << calc(n) << endl;

}

## Comments

## Leave a comment