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

Ответы 1

  • #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;

    }

    • Автор:

      marina64
    • 6 лет назад
    • 0
  • Добавить свой ответ

Еще вопросы

Войти через Google

или

Забыли пароль?

У меня нет аккаунта, я хочу Зарегистрироваться

How much to ban the user?
1 hour 1 day 100 years