Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 1

// timeformat.

c // Author : Pranil Kapadia // Date: 18th March 2012 // This is a program that will output time in various formats #include <stdio.h> #include <stdlib.h> int main(int argc, char * argv[]){ int hhmmss; int hours; int minutes; int seconds;

printf("Enter 24 hour time in HHMMSS format:\n"); scanf("%d", &hhmmss); hours = (hhmmss / 10000); minutes = (hhmmss % 10000) / 100; seconds = (hhmmss % 100); if(hours>=24 || minutes>=60 || seconds>=60){ printf("No such time!\n"); return(EXIT_FAILURE); } else { printf("The time is %02d:%02d:%02d ", hours, minutes, seconds); } printf("In 12 hour time it is %d:%02d:%02dam\n", hours, minutes, seconds);

return 0; }

You might also like