20. Convert a time in
24 hour clock to a time in 12 hour clock using structure.
#include <stdio.h>
#include<stdio.h>
#include<conio.h>
struct date
{
int hours,mins,seconds;
};
void main()
{
int status = 1;
struct date d;
clrscr();
printf( "Enter Hours (00-23):
"); scanf("%d", &d.hours);
printf("Enter Minutes (00-59):
"); scanf("%d", &d.mins);
printf("Enter Seconds (00-59):
"); scanf("%d", &d.seconds);
if((d.hours >= 24 || d.hours < 0))
{ printf("\nInvalid Hours..");
status=0; }
if((d.seconds >= 60 || d.seconds <
0))
{ printf("\nInvalid Seconds..");
status=0; }
if((d.mins >= 60 || d.mins < 0))
{ printf("\nInvalid Minutes..");
status=0; }
if(status==1)
{
printf("\n24 Hours Format\n");
printf("Hours: %d", d.hours);
printf("\nMinutes: %d", d.mins);
printf("\nSeconds: %d",
d.seconds);
}
if(d.hours > 12)
{
d.hours-=12;
printf("\n\n12 Hours Format\n");
printf("Hours: %dPM", d.hours);
printf("\nMinutes: %d", d.mins);
printf("\nSeconds: %d",
d.seconds);
}
else
{
printf("\n\n12 Hours Format\n");
printf("Hours: %dAM", d.hours);
printf("\nMinutes: %d", d.mins);
printf("\nSeconds: %d",
d.seconds);
}
getch();
}
No comments:
Post a Comment