C Program to print the AM and PM based on time

C Program to print the AM and PM based on time

Print the AM and PM based on time


Accept an integer n as input

For 0<=n && n<12

For 12<=n && n<24


For all other numbers, display "INVALID INPUT".


For example:


InputResult
0AM
13PM
24INVALID INPUT

Code
#include <stdio.h>

int main(){
    int n;
    scanf("%d",&n);
    if(0<=n && n<12){
        printf("AM");
    }
    else if(12<=n && n<24){
        printf("PM");
    }
    else{
        printf("INVALID INPUT");
    }
}

Other Programs

Load comments