Write a program that prompts the user to enter an integer and then displays that integer as a product of its primes and if it is a prime then it should say so??
Above is the question I have been given
#include <iostream>
#include <vector>
using namespace std;
int main ()
{
int num, result;
cout << "Enter A Number " << endl;
system ("pause");
return 0;
}
This is what I have so far, do I have to use a for loop, a while loop or a do loop,
and if it is possible can someone give me an example of how to it.
thanks very much appreciated
I have now changed my code to this,
#include <iostream>
using namespace std;
int main()
{
int n, c = 2;
printf("Enter a number to check if it is prime\n");
scanf("%d",&n);
for ( c = 2 ; c <= n - 1 ; c++ )
{
if ( n%c == 0 )
{
printf("%d is not prime.\n", n);
break;
}
}
if ( c == n )
printf("%d is prime.\n", n);
system ("pause");
return 0;
}
can anyone explain to me on how i can get the prime numbers shown of the number that is entered