| C Now | Modular Programs in C | ![]() |
/***************************************************************
* File: barith2.c
* Purpose: Program to report the results
* of boolean operations.
* Author: John Young
* Date: May 24, 2004
***************************************************************/
#include "boolean.h"
int main () {
And (0, 0);
And (0, 1);
And (1, 0);
And (1, 1);
Or (0, 0);
Or (0, 1);
Or (1, 0);
Or (1, 1);
EQ (0, 0);
EQ (0, 1);
EQ (1, 0);
EQ (1, 1);
NE (0, 0);
NE (0, 1);
NE (1, 0);
NE (1, 1);
Not (0);
Not (1);
return 0;
}
|
/*************************************************************** * File: boolean.h * Purpose: Interface for functions to report the results * of boolean operations. * Author: John Young * Date: May 24, 2004 ***************************************************************/ #ifndef boolean_h #define boolean_h void And (int A, int B); void Or (int A, int B); void EQ (int A, int B); void NE (int A, int B); void Not (int A); #endif |
/***************************************************************
* File: boolean.c
* Purpose: Implementation of functions to report the results
* of boolean operations.
* Author: John Young
* Date: May 24, 2004
***************************************************************/
#include <stdio.h>
#include "boolean.h"
void And (int A, int B) {
int Result;
Result = A && B;
printf ("%d && %d = %d\n", A, B, Result);
}
void Or (int A, int B) {
int Result;
Result = A || B;
printf ("%d || %d = %d\n", A, B, Result);
}
void EQ (int A, int B) {
int Result;
Result = A == B;
printf ("%d == %d = %d\n", A, B, Result);
}
void NE (int A, int B) {
int Result;
Result = A != B;
printf ("%d != %d = %d\n", A, B, Result);
}
void Not (int A) {
int Result;
Result = ! A;
printf ("! %d = %d\n", A, Result);
}
|
>cc barith2.cpp boolean.cpp Borland C++ 5.5 for Win32 Copyright (c) 1993, 2000 Borland barith2.cpp: boolean.cpp: Turbo Incremental Link 5.00 Copyright (c) 1997, 2000 Borland |
0 && 0 = 0 0 && 1 = 0 1 && 0 = 0 1 && 1 = 1 0 || 0 = 0 0 || 1 = 1 1 || 0 = 1 1 || 1 = 1 0 == 0 = 1 0 == 1 = 0 1 == 0 = 0 1 == 1 = 1 0 != 0 = 0 0 != 1 = 1 1 != 0 = 1 1 != 1 = 0 ! 0 = 1 ! 1 = 0 |
|
|
|
| |||||||