mirror of
https://github.com/cc65/cc65.git
synced 2025-02-10 09:31:08 +00:00
Calculate time in seconds, not ticks. Implement pager output for primes.
git-svn-id: svn://svn.cc65.org/cc65/trunk@3986 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
a3eed9016f
commit
043acb1d98
@ -35,10 +35,20 @@ static unsigned char Sieve[COUNT];
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
static char ReadUpperKey (void)
|
||||||
|
/* Read a key from console, convert to upper case and return */
|
||||||
|
{
|
||||||
|
return toupper (cgetc ());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
int main (void)
|
int main (void)
|
||||||
{
|
{
|
||||||
/* Clock variable */
|
/* Clock variable */
|
||||||
clock_t Ticks;
|
clock_t Ticks;
|
||||||
|
unsigned Sec;
|
||||||
|
unsigned Milli;
|
||||||
|
|
||||||
/* This is an example where register variables make sense */
|
/* This is an example where register variables make sense */
|
||||||
register unsigned char* S;
|
register unsigned char* S;
|
||||||
@ -70,19 +80,29 @@ int main (void)
|
|||||||
|
|
||||||
/* Calculate the time used */
|
/* Calculate the time used */
|
||||||
Ticks = clock() - Ticks;
|
Ticks = clock() - Ticks;
|
||||||
|
Sec = (unsigned) (Ticks / CLOCKS_PER_SEC);
|
||||||
|
Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC;
|
||||||
|
|
||||||
/* Print the time used */
|
/* Print the time used */
|
||||||
printf ("Time used: %lu ticks\n", Ticks);
|
printf ("Time used: %u.%03u seconds\n", Sec, Milli);
|
||||||
printf ("Press Q to quit, any other key for list\n");
|
printf ("Q to quit, any other key for list\n");
|
||||||
|
|
||||||
/* Wait for a key and print the list if not 'Q' */
|
/* Wait for a key and print the list if not 'Q' */
|
||||||
if (toupper (cgetc()) != 'Q') {
|
if (ReadUpperKey () != 'Q') {
|
||||||
/* Print the result */
|
/* Print the result */
|
||||||
|
J = 0;
|
||||||
for (I = 2; I < COUNT; ++I) {
|
for (I = 2; I < COUNT; ++I) {
|
||||||
if (Sieve[I] == 0) {
|
if (Sieve[I] == 0) {
|
||||||
printf ("%4d\n", I);
|
printf ("%4d\n", I);
|
||||||
|
if (++J == 23) {
|
||||||
|
printf ("Q to quit, any other key continues\n");
|
||||||
|
if (ReadUpperKey () == 'Q') {
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (kbhit() && toupper (cgetc()) == 'Q') {
|
J = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (kbhit() && ReadUpperKey == 'Q') {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user