Nov 5, 2009 at 12:21pm UTC
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;
}
Nov 5, 2009 at 2:43pm UTC
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 Nov 5, 2009 at 2:45pm UTC
Nov 5, 2009 at 4:13pm UTC
Like jsmith said, your result array isn't ever initialized to anything, which is why you are getting the error.