C - Write program to use logical OR operator inside if statement

Requirements

Write program to use logical OR operator inside if statement

Use logical OR operation to make the condition true when the value of variable coordinate is less than -5 or greater than 5.

Hint

The OR operator is ||

Demo

#include <stdio.h>

int main()//from   w  w  w  .  j a va  2  s. c om
{
    int coordinate;

    printf("Input target coordinate: ");
    scanf("%d",&coordinate);
    if( coordinate < -5 || coordinate > 5 )
    {
        puts("Close enough!");
    }
    else
    {
        puts("Target is out of range!");
    }
    return(0);
}

Result

Related Exercise