For example 1 3 5 7 9 11 17 19 you need to do

1 3 5 7 9

11 17 19

without the use of arrays, using an auxiliary variable, simple output numbers.

Closed due to the fact that off-topic participants rjhdby , pavel , Kromster , cheops , HamSter 19 Oct '16 at 6:35 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • “Questions asking for help with debugging (“ why does this code not work? ”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question . Questions without an explicit description of the problem are useless for other visitors. See How to create minimal, self-sufficient and reproducible example . " - rjhdby, pavel, cheops, HamSter
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • Give intelligible TK! What is given, in what form , what exactly needs to be done ... - Harry
  • ru.stackoverflow.com/questions/579338 I apologize for not saying right away, thinking and so it will be clear, this is a question to the previous task, the conclusion just goes there, but you need to optimize it by splitting into tens - FFF3_ZE
  • @ FFF3_ZE What is this sequence? How is it built and where does it come from? - Vlad from Moscow
  • one
    @ FFF3_ZE 9 is not a prime number. And we must immediately articulate the question, and not force others to read your comments on your own question in order to understand what you want. - Vlad from Moscow

2 answers 2

Well, since you need to divide prime numbers in dozens, then just add to the program you indicated in the comment:

int main(int argc, const char * argv[]) { int n = 100; cout << 2 << endl; for (int last = 2, j = 3; j < n; j+=2) { bool flag = true; if (j%2 == 0) continue; for (int a = 3; a*a <= j; a+=2) { if (j%a == 0) { flag = false; break; } } if (flag) { if (j/10 != last/10) cout << "\n"; cout << j << " "; last = j; } } } 

I hope everything is clear? When going through a dozen, we display a newline character ...

    If the source numbers are in a sorted array, then

     void print(int * nums, int cnt) { if (cnt == 0) return; int dec = nums[0] / 10; for (int i = 0; i < cnt; i++) { int cur_dec = nums[i] / 10; if (curdec != dec) { cout << endl; dec = cur_dec; } cout << num[i] << ' '; } } 
    • Unfortunately, they do not lie in the array, but they are sorted from the smallest to the largest and they seem to simplify the task. - FFF3_ZE
    • @ FFF3_ZE If not in an array, then where? Just a set of variables a , b , c , d ...? - Anton Shchyrov 4:05 pm
    • @AntonShchyrov I suspect that he has a cycle that calculates prime numbers. So your approach within this cycle will work fine. - Mike
    • @Mike is a beautiful assumption, but there he has a nine and no two :) - Anton Shchyrov