Q:

Write a program in C++ to display first 10 Fermat numbers

0

Write a program in C++ to display first 10 Fermat numbers

Sample Output:

 Display first 10 Fermat numbers:                                      
-------------------------------------                                  
 The first 10 Fermat numbers are:                                      
3                                                                      
5                                                                      
17                                                                     
257                                                                    
65537                                                                  
4.29497e+09                                                            
1.84467e+19                                                            
3.40282e+38                                                            
1.15792e+77                                                            
1.34078e+154                                                           
inf

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

# include <iostream>
# include <math.h>
using namespace std;
int main()
{
    int n=0;
	double result;
 cout << "\n\n Display first 10 Fermat numbers:\n";
 cout << "-------------------------------------\n";
cout << " The first 10 Fermat numbers are: "<<endl;
while (n <= 10) 
		{
            result= pow(2, pow(2, n)) + 1;
            n++;
            cout << result << endl;
        }
}

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Similar questions


need a help?


find thousands of online teachers now