I have this piece of code which should output all prime numbers to n(where n is the user input) separated by commas.
#include <iostream>
using namespace std;
void check(int a, int ra)
{
int count = 0;
for(int i = 1;i<=a;i++)
{
if(a%i==0)
count++;
}
if(count<3)
{
cout << a;
cout << ", ";
}
}
int main(int argc, const char * argv[]) {
int a;
cin >> a;
for(int i = 2;i<=a;i++)
check(i,a);
return 0;
}
Currently, it does everything alright except output looks like this (assume input is 10):
2, 3, 5, 7,
I need to get rid of comma after 7 and nothing I could think of worked.