Skip to content

Instantly share code, notes, and snippets.

@HamedMasafi
Created January 3, 2018 07:35
Show Gist options
  • Save HamedMasafi/6865dd3dfa3030bfbee7d3748f6429de to your computer and use it in GitHub Desktop.
Save HamedMasafi/6865dd3dfa3030bfbee7d3748f6429de to your computer and use it in GitHub Desktop.
// 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