w3resource
C Programming Exercises

C Exercises: Check whether two given integers are in the range 40..50 inclusive, or they are both in the range 50..60 inclusive

C-programming basic algorithm: Exercise-11 with Solution

Write a C program to check whether two given integers are in the range 40..50 inclusive, or they are both in the range 50..60 inclusive.

C Code:

#include <stdio.h>
#include <stdlib.h>
int main(void){
    printf("%d",test(78, 95));
    printf("\n%d",test(25, 35));
    printf("\n%d",test(40, 50));
    printf("\n%d",test(55, 60));
    }   
    
   int test(int x, int y)
        {
               return (x >= 40 && x <= 50 && y >= 40 && y <= 50) || (x >= 50 && x <= 60 && y >= 50 && y <= 60);

        }

Sample Output:

0
0
1
1

Flowchart:

C Programming Algorithm Flowchart: Check whether two given integers are in the range 40..50 inclusive, or they are both in the range 50..60 inclusive

Solution

Contribute your code and comments through Disqus.

Previous: Write a C program to check which number nearest to the value 100 among two given integers. Return 0 if the two numbers are equal.
Next: Write a C program to find the larger value from two positive integer values that is in the range 20..30 inclusive, or return 0 if neither is in that range.



New Content: Composer: Dependency manager for PHP, R Programming