Floating exception - can any one solve this problem please?

its a program for finding the prime numbers up to 100
can any one solve this problem..?


#include <iostream>
#include <string>


using namespace std;

int main()
{

int result[50];
int k=0;
for (int i = 3; i <= 100; i++)
{
bool isprime = true;
for (int j = 0; j <= sizeof(result); j++)
{
if (i % result[j] == 0)
{
isprime = false;
break;
}
}
if (isprime)
{
result[k]=i;
k++;
}

}
for(int d=0;d<sizeof(result);d++)
{
cout<<result[d]<<" ";
}
return 0;
}
 
for (int j = 0; j <= sizeof(result); j++)


causes access beyond end of results array.

BTW, the results array is never even initialized to anything, so it's likely you
are trying to do x % 0.
I was trying to do that, but i couldnt initialize , still the problem exists..
i did even by doing x%1, but i couldnt do it.
could any one help me please..?
Last edited on
Like jsmith said, your result array isn't ever initialized to anything, which is why you are getting the error.
Topic archived. No new replies allowed.