I want to make a simple program that will print out the factors of an integer. My program right now only outputs "The prime factors of 221 are 221, 221, 221, 221"... Where it should be "The prime factors of 221 are 1, 13, 17, 221" Any help would be awesome!
#include <cstdio>
int factorsOf(int x);
//function
int main()
{
int x = 221;
printf("The factors of 221 are ");
factorsOf(x);
return 0;
}
//function
int factorsOf(int x)
{
for(int i = 1; i <= 221; i++)
{
if (x%i == 0)
{
printf("%d, ", x);
}
}
return x;
}