programme to print the first ten Mesrenne number 1 3 7 15 31 63
Answers
Answered by
0
Answer:
I'll be coding the programme in C++ because nothing specific has been mentioned in the question However the logic remains the same.
Mersenne numbers are prime numbers which are also of the form 2^n - 1
So,
Program :
#include<iostream.h>
#include<conio.h>
#include<math.h>
void main()
{
clrscr();
unsigned long int a,b;
int k=0,i=1,counter=1;
while(k!=11)
{
a = pow(2,i)-1;
for(b=2;b<=a;b++)
{
if(a%b=0)
{
counter=0;
}
}
if(counter==1)
{
cout<<". "<<a;
k++;
}
i++;
}
cout<<" \nThese are the first ten Mersenne numbers ";
getch();
}
Similar questions