Here is my code adopted from a simple C++ IO program from a basic learning C++ book using Quincy as my developer environment and of course gcc.
//
// A Simple C++ program For Integrating a random variable (X^2) and finding its expected value or mean.//
#include
int main()
{
int Kvalue;
float Svalue;
int Seed;
float U;
int countK;
float Expected;
std::cout << "Enter integer for random seed: ";
std::cin >> Seed;
void srand(unsigned int Seed);
std::cout << "Enter integer for length of Integral: ";
std::cin >> Kvalue;
countK=0;
Svalue = 0;
while (Kvalue >= countK)
{
float rand(U);
Svalue= Svalue + U*U;
countK++;
}
Expected= Svalue/Kvalue;
std::cout << "Expected Value = ";
std::cout << Expected;
std::cout << "Svalue = ";
std::cout << Svalue;
std::cout << "Kvalue = ";
std::cout << Kvalue;
return 0;
}
No comments:
Post a Comment