Jan 27, 2018 at 7:09pm UTC
I'm trying to add the numbers that are both factors and prime into a list, but I keep getting an error at the given lines so if anyone can give me tips on how to fix/improve my code, it would be greatly appreciated.
#include <iostream>
#include "integerManipulation.h"
#include "primeFactorization.h"
#include <cmath>
using namespace std;
void primeFactorization::factorization()
{
if (isPrime(num))
cout << num << "is not a prime number";
else
cout << num << "Is a prime number" << endl;
primeFact(num);
}
primeFactorization::primeFactorization(long long n)
: integerManipulation(n)
{ //thread 1 exc_bad_access (code=1 address=0x7ffeef
first125000PrimeNum(first125000Primes, 125000); */thread 1 exc_bad_access (code=1 address=0x7ffeef) */
}
void primeFactorization::primeFact(long long num)
{
int length = 2;
int i = 0;
int maxNum = sqrt(num);
while (length < maxNum)
{
if (num % length && isPrime(num) == 0)
{
first125000Primes[i] = length; */ thread 1 exc_bad_access (code=1 address=0x7ffeef) */
i++;
}
length++;
}
cout << first125000Primes << endl;
}
void primeFactorization::first125000PrimeNum(long long list[], int length = 0)
{
for (long long i = 2; i < 125000; i++)
{
if (primeFactorization::isPrime(i) == true)
{
first125000Primes[length] = i; */ thread 1 exc_bad_access (code=1 address=0x7ffeef) */
length++;
}
}
}
bool primeFactorization::isPrime(long long number)
{
if (number < 1 || number % 2 == 0 || number % 3 == 0)
return false;
else
return true;
}
include <iostream>
#include "primeFactorization.h"
using namespace std;
int main() {
primeFactorization number; */ thread 1 exc_bad_access (code=1 address=0x7ffeef) */
long long num;