Computers in Engineering WWW Site - Example 1.1

Example 11.1


C Version

/*
   Demonstration of logical operations in C.
*/

#include <stdio.h>

main()
{
  /*  Declaration Statements  */

  int heavy, minor;    /* Really logical/boolean  */
  short kilos, age;

  /*  Assignment Statements  */

  printf("C31.C -> Demonstration of logical operations in C.\n");
  printf("Enter Weight :");
  scanf("%hd", &kilos);
  printf("Enter Age :");
  scanf("%hd",&age);
  getchar();
  heavy = (kilos > 90);   /* Heavy and minor will be assigned a */
  minor = (age < 18);     /* logical value true or false.       */

  /*  Print Results  */

  printf("%d %s\n", kilos, heavy ? " TRUE" : "FALSE");
  printf("%d %s\n", age, minor ? " TRUE" : "FALSE");

  return(0);
}
/*  End of Program C31  */
/*
INPUT :
210
57

OUTPUT :
C31.C -> Demonstration of logical operations in C
Enter Weight :210
Enter Age :57
210 TRUE
57 FALSE

*/

Last modified: 21/07/97