//
// A C++ program For Integrating a random variable (X^2) and finding its expected value or mean.//
#include
int Kvalue;
int Svalue;
int Seed;
int U;
int countK;
float Expected;
int main()
{
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)
{
U= 1 + (int) ( 10.0 * rand() / (RAND_MAX + 1.0) );
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