The First N Fibonacci Numbers

Easy

Read an integer N and print the first N Fibonacci numbers on one line separated by single spaces, with no space after the last one and a newline at the end. The first two terms are 0 and 1, and every later term is the sum of the two before it, so N of 10 prints 0 1 1 2 3 5 8 13 21 34. Keep the terms in long variables. N must be between 1 and 45 so that every term the loop forms fits in a 32-bit long; otherwise print N must be between 1 and 45 and return 1. If N cannot be read, print invalid input and return 1.

Success Criteria

Your code must pass 7 test case(s) to complete this exercise. 3 hint(s) are available if you need help.

Sign in to track your progress

You can work on exercises as a guest, but sign in to track your progress and save your submissions.

This platform is built by its community

Every lesson, project, and tool on HelloC++ is funded by sponsors. Join them and help shape what we build next.

Become a Patron

How did you find this exercise?

Your rating helps us improve the content.