For loop prints an extra comma

Use

cout << "Set B : {";

for (i = 0; i < b; ++i) {
  if (i > 0) cout << ",";

  cout << setB[i];
}

cout << " }" << endl;

I changed your algorithm :

Before it meant : “Put the number and then put a comma”

Now it means : “If there is a number behind me put a comma, then put the number”

Before, you always printed a comma when you printed a number so you had an extra comma.

Leave a Comment