#include #include using namespace std; /* * fibonacciFromFile.cpp created 16:14 on 26th August 2005 author Sara Collins * * Program to calculate the fibonacci sequence for a specified number * to a specified order and output to a file. The inputs are also * read in from a file. */ int main(int argc, char *argv[]){ //check the correct number of arguments have been passed. if(argc != 3 || strcmp(argv[1],"--help") == 0){ cerr << "Usage : " << argv[0] << " " <> num_str; inputfile >> order_str; cout << "Read in "< 1) file << number << endl; double fib = number; double fib_prev = 1; //calculate the next values and output for(unsigned int i = 3; i <= order; i++){ double fib_next = fib*number + fib_prev; file << fib_next << endl; fib_prev = fib; fib = fib_next; } //close the file file.close(); return 0; }