7

Unary tests

  1. #include "min.h"
  2.  
  3. #include <stdlib.h>
  4. #include <stdio.h>
  5.  
  6. #ifdef DEBUG
  7. int debug = 0;  // 0 - off, 1 - on
  8. #endif
  9.  
  10. #ifdef DEBUG
  11. #define ONDEBUG( expr ) do { if ( debug ) { expr; } } while ( 0 )
  12. #else
  13. #define ONDEBUG( expr )
  14. #endif
  15.  
  16. int min( int x, int y ) {
  17.     ONDEBUG( printf("min(%d, %d)\n", x, y); );
  18.  
  19.     return x < y ? x : y;
  20. }
  21.  
  22. #if defined( STANDALONE )
  23.  
  24. int main() {
  25.     int a, b;
  26.  
  27.     printf("Enter 2 numbers at the prompt or ^Z|^D.\n");
  28.     for( ;; ) {
  29.         printf("\n? ");
  30.         switch( scanf( "%d %d", &a, &b ) ) {
  31.             case -1:
  32.                 exit(0);
  33.             case 2:
  34.                 printf(" = %d", min( a, b));
  35.                 break;
  36.             default:
  37.                 scanf( "%*s" ); /* swallow bad input */
  38.                 break;
  39.         }
  40.     }
  41.  
  42.     exit(0);
  43. }
  44.  
  45. #endif
  1. #if !defined( _MIN_H )
  2. #define _MIN_H
  3.  
  4. int min( int, int );
  5.  
  6. #endif

Comments

Your comment:
[p] [b] [i] [u] [s] [quote] [pre] [br] [code] [url] [email] strip help 2000

Enter a maximum of 2000 characters.
Improve the presentation of your text with the following formatting tags:
[p]paragraph[/p], [b]bold[/b], [i]italics[/i], [u]underline[/u], [s]strike[/s], [quote]citation[/quote], [pre]as is[/pre], [br]line break,
[url]http://www.izend.org[/url], [url=http://www.izend.org]site[/url], [email]izend@izend.org[/email], [email=izend@izend.org]izend[/email],
[code]command[/code], [code=language]source code in c, java, php, html, javascript, xml, css, sql, bash, dos, make, etc.[/code].