You can use
if (a != 2)
cout<<"2*";
else
cout<<"2";
instead of cout<<"2*";
solved How to prevent a final cout in a loop from being executed?
You can use
if (a != 2)
cout<<"2*";
else
cout<<"2";
instead of cout<<"2*";
solved How to prevent a final cout in a loop from being executed?