#help me

13 messages · Page 1 of 1 (latest)

potent spade
#

#include <iostream>
#define MAX 10000
#define LOG(X) std::cout << X << std::endl
#define CIN(X) std::cin >> X

int m;
int j = 0;

void number(int* cells)
{
if (j >= m)
{
return;
}

for (int i = j; i < m; i = i + j)
{
    if (cells[i] == 0)
    {
        cells[i] = 1;
    }
    else
    {
        cells[i] = 0;
    }
}
j = j + 1;
number(cells);

}

int main()
{
int n;
int* cell = new int[MAX];
LOG("please enter your cell number:");
CIN(n);

if (n <= 0 || n > MAX) 
{
    LOG("error!");
    delete[] cell; 
    return 1;
}

m = n;
for (int i = 0; i < n; i++)
{
    cell[i] = 0;
}
number(cell);
for (int i = 0; i < n; i++)
{
    LOG(cell[i]<<"\n");
}

delete[] cell; 
return 0;

}

astral anvilBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question use !howto ask.

potent spade
#

can run, but can't get the result

potent spade
#

yes ,I know it's may for statement

astral anvilBOT
#
#include <iostream>
#define MAX 10000
#define LOG(X) std::cout << X << std::endl
#define CIN(X) std::cin >> X

int m;
int j = 0;

void number(int* cells) {
  if (j >= m) {
    return;
  }

  for (int i = j; i < m; i = i + j) {
    if (cells[i] == 0) {
      cells[i] = 1;
    } else {
      cells[i] = 0;
    }
  }
  j = j + 1;
  number(cells);
}

int main() {
  int n;
  int* cell = new int[MAX];
  LOG("please enter your cell number:");
  CIN(n);

  if (n <= 0 || n > MAX) {
    LOG("error!");
    delete[] cell;
    return 1;
  }

  m = n;
  for (int i = 0; i < n; i++) {
    cell[i] = 0;
  }
  number(cell);
  for (int i = 0; i < n; i++) {
    LOG(cell[i] << "\n");
  }

  delete[] cell;
  return 0;
}
Northy-sukura
foggy vector
#

And what are you getting right now?

potent spade
#

just need to change i=i+j+1 in the for-statement

astral anvilBOT
#

@potent spade Has your question been resolved? If so, type !solved :)

potent spade
#

@astral anvil!solved