Информатика, вопрос задал therakong , 7 лет назад

Помогите с задачей по C++.
Дано ціле число N (> 0). Використовуючи один цикл, знайти суму
1 + 1 / (1!) + 1 / (2!) + 1 / (3!) +. . . + 1 / (N!)

Ответы на вопрос

Ответил MupoTBopec
0

#include "iostream"

#include "stdlib.h"

using namespace std;

int main(){

int N;

float result = 1, factorial = 1;  

cout << "Enter integer more than 0: "; cin >> N;

if(N > 0){

 for (int i = 1; i < N+1; i++){

 factorial = factorial * i;

 result = result + 1/(factorial);

 cout << result << endl;

}

cout << "Result: " << result << endl;

}else cout << "You entered integer less than 0" << endl;

system("pause");

return 0;

}

Новые вопросы