mirror of
https://github.com/epasveer/seer.git
synced 2026-08-30 00:50:42 +08:00
c84dd60a7e
Add the 'if' word to the dialogs. Parse the breakpoints table more effieciently.
46 lines
860 B
C++
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;
|
|
}
|
|
|