EULER Q2 Solution

 #include <iostream>

using namespace std;

int LargestPrime(int);

int LargestPrime(int TheNum)
{
int FactorCount = 0;

for (int i=TheNum; i>=2; --i)
{

for (int j=2; j<i; ++j)
{
if (i % j == 0)
{
++FactorCount;
}
}

if (FactorCount == 0)
{
return i;
break;
}

FactorCount = 0;
}
return 0;
}


int main()
{
int Input, Result;
cout << "Enter the number: ";
cin >> Input;
Result = LargestPrime(Input);

cout << "The largest prime number before " << Input << " is " << Result << endl;
return 0;
}

Comments

Popular posts from this blog

OOP Assignment 3 helping materials

Square root Algorithm in C++

OOP lab 7 task solution