ifor.c

#include <stdio.h>

int main()
{
   int x;
   printf("Input x: "); scanf("%d", &x);
   if ((x > 0) || (x % 2 == 0))
       printf("x is either positive or even.\n");
   else
       printf("Invalid values of x detected!\n");
   return 0;
}
  • This example is the same as before except the highlighted part. We now use or operator instead and change the message.
  • We then again try running this example a few times with the same input: -2, -1, 0, 1, and 2.
  • Their respective output was:
       x is either positive or even.
       Invalid values of x detected!
       x is either positive or even.
       x is either positive or even.
       x is either positive or even.
  • Why?

 


Where to go

Chapter 2
News Page
Lesson 1 contents
Contacting Me


Roby Joehanes © 2001

Hosted by www.Geocities.ws

1