This is what I have so far of a c++ program to compute the factors of an input i
ID: 3651891 • Letter: T
Question
This is what I have so far of a c++ program to compute the factors of an input integer. What I'm stuck on is making the program repeat after the production of factors and how i would make the program say if a number is prime or not./*
File: factors.cpp
Created By:
Created On: 10/10/12
Synopsis:
*/
#include <iostream>
#include <iomanip>
#include <cstdlib>
using namespace std;
int main ()
{
int num = 0;
int count = 0;
int a = 1;
cout << "Enter an integer (0 to exit): ";
cin >> num;
while(num < 0)
{
cerr << "Illegal negative number."<< endl;
cout << "Enter an integer (0 to exit): ";
cin >> num;
}
if(num==0)
{
exit(10);
}
cout << "Factors of " << num << ": ";
for (int a = 1;a<=num; a++)
{
while (num % a ==0)
{
cout << a << " ";
a++;
}
}
return 0;
}