T
T
TolikSakhovsky2018-10-28 20:44:58
C++ / C#
TolikSakhovsky, 2018-10-28 20:44:58

Can I somehow do without initializing the variable?

Can I somehow do without initializing the n variable?

#include<iostream>
#include<cstdlib>
using namespace std;
int main() {
  system("chcp 1251>nul");
  int n;
  cout << "n " << n;
  cin >> n;
  int k = 1;
  while (k < n) {
    k = k * (n - k) / (k + 1);
    cout << " " << k++;
    k++;
  }
  cout << endl;
  system("pause");
  return 0;
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2018-10-29
Yazovskikh @unepic

No. You have a cycle up to n, the value of which is not known in advance. Or you are asking the wrong question.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question