السلام عليكم.
كنت باحل الاسئلة اللى فى كتاب ال C++ how to program.
كان فى سؤال فى باب ال Control structure عن حساب قيمة الثابت الرياضى e من المتسلسلة الشهيرة :
e = 1 + (1/1! ) + (2/2!) + (3/3!) + ............................... etc
عن طريق ال while loop
هذا هوالكود اللى كتبته
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
int Fac(int);
void e();
int main()
{
e();
return 0;
}
int Fac(int x)
{
int y = 1;
while(x>1)
{
y *= x;
x--;
}
return y;
}
void e()
{
int counter = 1;
double e = 1.0;
while( counter > 0 )
{
int y;
y = Fac(counter);
e += static_cast<double>(1) / y;
counter++;
cout << e<< endl;
}
}وهذه هى المخرجات
ايه الحاجات العجيبة دى!!!!!!!!!