Program: 118
Write a c program to print 24 hours of day with suitable suffixes like AM, PM, Noon and Midnight.
#include<stdio.h> #include<conio.h> int main() { int h; //for-loop for 24 hours for(h=0;h<=23;h++) { if(h==0) { printf("12 Midnight\n"); continue; } if(h<12) { printf("%d AM\n",h); } if(h==12) { printf("%d Noon\n",h); } if(h>12) { //h=h%12; printf("%d PM\n",h%12); } } }
Output:
12 Midnight 1 AM 2 AM 3 AM 4 AM 5 AM 6 AM 7 AM 8 AM 9 AM 10 AM 11 AM 12 Noon 1 PM 2 PM 3 PM 4 PM 5 PM 6 PM 7 PM 8 PM 9 PM 10 PM 11 PM
Leave a Comment