Strange output produced by program

Posted by Boom_mooB on Stack Overflow See other posts from Stack Overflow or by Boom_mooB
Published on 2012-10-30T19:53:00Z Indexed on 2012/10/30 23:01 UTC
Read the original article Hit count: 109

Filed under:
|
|

I think that my code works. However, it outputs 01111E5, or 17B879DD, or something like that.

Can someone please tell me why.

I am aware that I set the limit of P instead of 10,001. My code is like that because I start with 3, skipping the prime number 2.

#include <iostream>
bool prime (int i)
{
bool result = true;
int isitprime = i;
for(int j = 2; j < isitprime; j++)              ///prime number tester
{
    if(isitprime%j == 0) result = false;
}   
return result;
}


int main (void)
{
using namespace std;
int PrimeNumbers = 1;
int x = 0;
for (int i = 3 ; PrimeNumbers <=10000; i++)
{
    if(prime(i))
    {
        int prime = i;
        PrimeNumbers +=1;
    }
}   
cout<<prime<<endl;
system ("pause");
return 0;
}

© Stack Overflow or respective owner

Related posts about c++

Related posts about visual-c++