is this output correct?
i am checking for messene primes.
Code:
#include <iostream>
#include <iomanip>
using namespace std;
bool IsPrime (long n );
long power2 ( long n );
int main()
{
char reply;
cout << "Mersenne Primes by corey" << endl;
cout << endl;
cout << "n" << setw(30) << setfill(' ') << "Mersene Prime" << endl;
cout << "==" << setw(29) << setfill(' ')<< "=============" << endl;
for ( int i = 0; i < 100; i++ ) {
if ( IsPrime ( i ) )
power2(i);
}
cin >> reply;
return 0;
}
bool IsPrime(long n)
{
int i = 0;
int counter = 0;
for ( i = 1; i <= n; i++ )
{
if ( n % i == 0 )
{
counter++;
}
}
if (counter == 2)
return true;
else
return false;
}
long power2 ( long n )
{
cout << n << setw(30) << setfill(' ') << (1L << n) - 1 << endl;
return 0;
}
output:
Code:
Mersenne Primes by corey
n Mersene Prime
== =============
2 3
3 7
5 31
7 127
11 2047
13 8191
17 131071
19 524287
23 8388607
29 536870911
31 2147483647
37 31
41 511
43 2047
47 32767
53 2097151
59 134217727
61 536870911
67 7
71 127
73 511
79 32767
83 524287
89 33554431
97 1
thank you