/**************************************************************** * Name: main * * Synopsis: Entry point for all Concordance programs. * ****************************************************************/ main() { char key; char mark[10000]; int i, n, num, step, start, file; text line; /* Initialize screen and open data base. */ initialize(); file = open("con","w"); cursor(3,0); puts(0,0,"This program calculates and displays the prime numbers"); puts(1,0,"between 3 and 1000. It then displays how long it took."); puts(2,0,"Press any key to begin..."); getkey(); start = clock(); num = 0; for(n = 3; n < 1000; n = n + 2) if(mark[n] == 0) { write(file,str(n,5,0),5); step = 2 * n; for(i = 3 * n; i < 1000; i = i + step) mark[i] = -1; num = num + 1; } line = "It takes "+str((clock() - start)/1000)+" seconds to find "+ str(num)+" primes."; writeln(file,"",0); writeln(file,line,len(line)); close(file); getkey(); } /* main() */ /**************************************************************** * Name: initialize * * Synopsis: Set global variables to initial values * * Action: Global variables are set for system calls * ****************************************************************/ int color, ESC; initialize() { color = 31; ESC = 27; clsc(color); cursor(0,0); } /* initialize() */ /**************************************************************** * Name: clsc * * Synopsis: Clear the screen * * Results: Screen is cleared * * Error: None * * Parameters: Screen color * * Action: Scroll() is called to clear the entire screen * ****************************************************************/ clsc(int color) { scroll(0, 0, 24, 79, 0, 1, color); } /* clsc() */