#include<stdio.h>
#include<conio.h>
//Declaration of structure time_struct
struct time_struct{
int hour,minute,second;
}time;
//Member time declared
void main()
{
int i;
clrscr();
//Data input from user
printf("\nEnter the time in hour, minute and second format");
scanf("%d%d%d",&time.hour,&time.minute,&time.second);
//Formating of the inserted data
if(time.minute>60 || time.second>60)
printf("\nPlease enter valid time format");
else
{
printf("\nEntered Time is :");
if(time.hour<=9 && time.minute<=9 && time.second<=9)
printf("\n0%d:0%d:0%d",time.hour,time.minute,time.second);
else if(time.hour<=9 && time.minute>9 && time.second>9)
printf("\n0%d:%d:%d",time.hour,time.minute,time.second);
else if(time.hour>9 && time.minute<=9 && time.second>9)
printf("\n%d:0%d:%d",time.hour,time.minute,time.second);
else if(time.hour>9 && time.minute>9 && time.second<=9)
printf("\n%d:%d:0%d",time.hour,time.minute,time.second);
else if(time.hour<=9 && time.minute<=9 && time.second>9)
printf("\n0%d:0%d:%d",time.hour,time.minute,time.second);
else if(time.hour<=9 && time.minute>9 && time.second<=9)
printf("\n0%d:%d:0%d",time.hour,time.minute,time.second);
else if(time.hour>9 && time.minute<=9 && time.second<=9)
printf("\n%d:0%d:0%d",time.hour,time.minute,time.second);
else
printf("\n%d:%d:%d",time.hour,time.minute,time.second);
}
getch();
} |