Entered time is valid or not

C program to check whether the time is valid or not.

Program

#include<stdio.h>
#include<conio.h>
void main()
{
	int hour, min, sec;

    printf("Enter the time in hour, minute and second\t:");
    scanf("%d%d%d",&hour,&min,&sec);

    if((hour >= 0 && hour <= 24) && (min >= 0 && min <= 60) && (sec >= 0 && sec <= 60))
		printf("\nTime entered is valid");
    else
		printf("\nTime entered is not valid");

    getch();
}

Output

********** Run1 ********** 

Enter the time in hour, minute and second       :23
45
56

Time entered is valid


********** Run2 ********** 

Enter the time in hour, minute and second       :32
34
45

Time entered is not valid

Explanation

For time to be valid, following conditions must be met
hours value must be in the range 0 to 24
minutes value must be between 0 to 60
seconds value must be in the range 0 to 60
If all the above 3 conditions are true, then the time is valid. If any of the above conditions is false, then time is not valid. To ensure all the three conditions are true, Logical AND (&&) operator is used in between the conditions,
if((hour >= 0 && hour <= 24) && (min >= 0 && min <= 60) && (sec >= 0 && sec <= 60))