Created
January 3, 2018 07:35
-
-
Save HamedMasafi/6865dd3dfa3030bfbee7d3748f6429de to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Example program | |
#include <iostream> | |
#include <string> | |
float n; | |
float p; | |
float f0; | |
float f(int k) { | |
if ( k == 0 ) | |
return f0; | |
else | |
return (p / (1 - p)) * ((n - k + 1) / (k)) * f(k - 1); | |
} | |
int main() | |
{ | |
std::cout << "Enter p:"; | |
std::cin >> p; | |
std::cout << "Enter n:"; | |
std::cin >> n; | |
std::cout << "Enter f(0):"; | |
std::cin >> f0; | |
std::cout << "f(0):" << f0 << std::endl; | |
for (int i = 1; i <= n; i++) | |
std::cout << "f(" << i << "):" << f(i) << std::endl; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment