mirror of
https://github.com/cc65/cc65.git
synced 2025-02-05 20:31:53 +00:00
Made div-test.c use doesclrscrafterexit().
It no longer waits for a key tap if it doesn't need to do that. Also, normalized the source code formatting.
This commit is contained in:
parent
8fd1db4d78
commit
2acfa5e78f
@ -2,37 +2,44 @@
|
||||
**
|
||||
** This program tests the division and modulo operators
|
||||
** and the div() library function.
|
||||
**
|
||||
** 2002-10-24, Greg King
|
||||
*/
|
||||
|
||||
#include <cc65.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
static bool test(int dividend, int divisor) {
|
||||
div_t result;
|
||||
static bool test (int dividend, int divisor)
|
||||
{
|
||||
div_t result;
|
||||
|
||||
result = div(dividend, divisor);
|
||||
printf("%+d/%+d= %+d, %+d%%%+d= %+d, div()= %+d, %+d\n",
|
||||
dividend, divisor, dividend / divisor,
|
||||
dividend, divisor, dividend % divisor,
|
||||
result.quot, result.rem);
|
||||
return result.quot * divisor + result.rem != dividend;
|
||||
}
|
||||
result = div (dividend, divisor);
|
||||
printf ("%+d/%+d= %+d, %+d%%%+d= %+d, div()= %+d, %+d\n",
|
||||
dividend, divisor, dividend / divisor,
|
||||
dividend, divisor, dividend % divisor,
|
||||
result.quot, result.rem);
|
||||
|
||||
int main(void) {
|
||||
bool t;
|
||||
return result.quot * divisor + result.rem != dividend;
|
||||
}
|
||||
|
||||
printf("\nTest of division and modulus operations:\n\n");
|
||||
t = test(+40, +3) ||
|
||||
test(+40, -3) ||
|
||||
test(-40, +3) ||
|
||||
test(-40, -3);
|
||||
if (t)
|
||||
printf("\nThe div() function made a wrong result!\n");
|
||||
int main (void)
|
||||
{
|
||||
bool t;
|
||||
|
||||
printf("\nTap a key, to exit. ");
|
||||
getchar();
|
||||
return (int)t;
|
||||
}
|
||||
printf ("\nTest of division and modulus operations:\n\n");
|
||||
|
||||
t = test (+40, +3) ||
|
||||
test (+40, -3) ||
|
||||
test (-40, +3) ||
|
||||
test (-40, -3);
|
||||
if (t) {
|
||||
printf ("\nThe div() function made a wrong result!\n");
|
||||
}
|
||||
|
||||
if (doesclrscrafterexit ()) {
|
||||
printf ("\nTap the Return key to quit. ");
|
||||
getchar ();
|
||||
}
|
||||
|
||||
return (int)t;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user