Ma’lumotlar tuzilmasi va algoritmi F.I.SH.___________________________________________ Guruh: __________________________________________ Amaliyot: _____X_______ Misol: ______X_________ Dasturlash tili: ________________X__________________
Savol : n butun soni va x haqiqiy soni berilgan (n > 0). Quyidagi yig'indini hisoblovchi programma tuzilsin. (Olingan natija taxminan ex ga yaqinlashadi)
1 + x + x2 / (2!) + x3 / (3!) + ... +xn /(n!)
1 + x + x2 / (2!) + x3 / (3!) + ... +xn /(n!)
#include using namespace std;
int main() {
setlocale(LC_ALL, "Russian");
float x;
cout<<"X:";
cin>>x;
int n;
cout<<"N:";
cin>>n;
float x1 = 1, n1 = 1, rez = 1.0;
int i;
for (i = 1; i <= n; ++i) {
n1 *= (float)i;
x1 *= x;
rez += x1 / n1;
}
cout<< rez;
}