C Exercises: Display first 10 Fermat numbers
C Numbers: Exercise-30 with Solution
Write a program in C to display first 10 Fermat numbers.
Sample Solution:
C Code:
# include <stdio.h>
# include <stdlib.h>
# include <math.h>
int main()
{
int n=0;
double result;
printf("\n\n Display first 10 Fermat numbers:\n");
printf("-------------------------------------\n");
printf(" The first 10 Fermat numbers are: \n");
while (n <= 10)
{
result= pow(2, pow(2, n)) + 1;
n++;
printf("%lf \n",result);
}
}
Sample Output:
The first 10 Fermat numbers are: 3.000000 5.000000 17.000000 257.000000 65537.000000 4294967297.000000 18446744073709551616.000000 340282366920938463463374607431768211456.000000 115792089237316195423570985008687907853269984665640564039457584007913129639936.000000 13407807929942597099574024998205846127479365820592393377723561443721764030073546976801874298166903427690031858 186486050853753882811946569946433649006084096.000000 inf
Pictorial Presentation:
Flowchart:
C Programming Code Editor:
Contribute your code and comments through Disqus.
Previous: Write a program in C to check whether a given number is a perfect cube or not.
Next: Write a program in C to find any number between 1 and n that can be expressed as the sum of two cubes in two (or more) different ways.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource's quiz.
C Programming: Tips of the Day
Static variable inside of a function in C
The scope of variable is where the variable name can be seen. Here, x is visible only inside function foo().
The lifetime of a variable is the period over which it exists. If x were defined without the keyword static, the lifetime would be from the entry into foo() to the return from foo(); so it would be re-initialized to 5 on every call.
The keyword static acts to extend the lifetime of a variable to the lifetime of the programme; e.g. initialization occurs once and once only and then the variable retains its value - whatever it has come to be - over all future calls to foo().
Ref : https://bit.ly/3fOq7XP
- New Content published on w3resource:
- HTML-CSS Practical: Exercises, Practice, Solution
- Java Regular Expression: Exercises, Practice, Solution
- Scala Programming Exercises, Practice, Solution
- Python Itertools exercises
- Python Numpy exercises
- Python GeoPy Package exercises
- Python Pandas exercises
- Python nltk exercises
- Python BeautifulSoup exercises
- Form Template
- Composer - PHP Package Manager
- PHPUnit - PHP Testing
- Laravel - PHP Framework
- Angular - JavaScript Framework
- Vue - JavaScript Framework
- Jest - JavaScript Testing Framework