I have this program that prints all the prime digits that are present in a number in the order of their apparition from right to left. That part was simple enough.
The book wants that at the end the program to output the numbers in the console like this:"2 and 3 and 7" for example. I don't know how to implement that.
using namespace std;
int main()
{
int n,digit;
cin>>n;
while (n>0)
{
digit=n%10;
if (digit==2 || digit==3 || digit==5 || digit==7)
cout<<digit<<"and"<<endl;
n=n/10;
}
}
This produces one extra "and" at the ending that I don't want.