C program to check whether the time is valid or not - IProgramX

Q. Accept the time as hour, minute and seconds and check whether the time is valid. (Hint:0<=hour<24, 0<=minute <60, 0<=second <60)



Program

#include <stdio.h>
main()
{
              int h , m ,s;
              printf("Enter time in format hh mm ss\n");
              scanf("%d%d%d",&h,&m,&s);

              if((h>=0&&h<24)&&(m>=0&&m<60)&&(s>=0&&s<60))

                             printf("Valid\n");
              else
                             printf("Invalid\n");
}

Output:

Enter time in format hh mm ss
12 45 56
Valid

Post a Comment

0 Comments