#include #include #include #include #include #include void initcurses(void); void shutdowncurses(void); long double fib(unsigned long index); int main(int argc, char *argv[]) { long i; long double result = 0; time_t starttime; time_t endtime; initcurses(); atexit(shutdowncurses); starttime = time(NULL); mvaddstr(0, 0, "Started: "); mvaddstr(0, 9, ctime(&starttime)); refresh(); for (i = 0; i < 1000000; ++i) { long double tmp; static double percentage = 0; static double tmppercentage = 0; char msg[16]; tmp = fib(i); if (floor(tmp / 2.0) == tmp / 2.0) result += tmp; tmppercentage = i / 1000000.0 * 100.0; if (floor(tmppercentage * 100) > floor(percentage * 100)) { percentage = tmppercentage; memset(msg, 0, 16); snprintf(msg, 16, "Percent: %.2f", percentage + 1); mvaddstr(1, 0, msg); refresh(); } } endtime = time(NULL); mvaddstr(2, 0, "End Time: "); mvaddstr(2, 11, ctime(&endtime)); mvaddstr(3, 0, "Press return to exit..."); refresh(); while (getch() != (int)'\n'); return 0; } void initcurses(void) { initscr(); noecho(); cbreak(); keypad(stdscr, TRUE); } void shutdowncurses(void) { echo(); nocbreak(); keypad(stdscr, FALSE); endwin(); } long double fib(unsigned long index) { long double n1 = 1; long double n2 = 2; unsigned long i; for (i = 0; i < index; ++i) { if (n1 < n2) n1 += n2; else n2 += n1; } return (n1 < n2) ? n2 : n1; }