S
S
Swordwhile2019-04-16 20:07:37
C++ / C#
Swordwhile, 2019-04-16 20:07:37

Why does the program only calculate once?

#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  setlocale(LC_ALL , "ru");
  float P = 1,M,i,r;
  int k = 2;
  cout << "Введите число М" << endl;
  cin >> M;
  do 
  {
    int f=1;
    for ( f,i = 1; i <= 2 * k + 1; i++)f *= i;
    float t=1;
    for (t, i = 1; i <= k - 1; i++)t *= i;
    r = f / t;
    P*= r;
    k++;
  } while (r <= M);
  {
    cout << P << endl;
    
    return 0;
  }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
V
vanyamba-electronics, 2019-04-17
@vanyamba-electronics

That's right. r = 120. Therefore, M must be a multiple of 120.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question