Files
seer/tests/hellofibonacci/hellofibonacci.cpp
T
Ernie Pasveer c84dd60a7e Cosmetic changes for specifying conditions in breakpoints.
Add the 'if' word to the dialogs.
Parse the breakpoints table more effieciently.
2023-11-24 13:11:49 -06:00

46 lines
860 B
C++

#include <iostream>
#include <stdlib.h>
int main (int argc, char* argv[]) {
if (argc != 2) {
std::cout << "usage: " << argv[0] << " N" << std::endl;
return 1;
}
int t1 = 0;
int t2 = 1;
int nextTerm = 0;
int n = atoi(argv[1]);
// Check N
if (n < 0) {
std::cout << "Bad value of 'N': " << argv[1] << std::endl;
return 1;
}
// Displays the first two terms which is always 0 and 1
std::cout << "Fibonacci Series: " << t1 << ", " << t2 << ", ";
// Display next terms.
nextTerm = t1 + t2;
while (nextTerm <= n) {
std::string s = "";
s = std::to_string(nextTerm);
std::cout << s << ", ";
t1 = t2;
t2 = nextTerm;
nextTerm = t1 + t2;
}
// Final EOL
std::cout << std::endl;
return 0;
}