In C language
Write a program that: simulates a time clock does nested for
loops with one
switch statement.
Declares variables hours, minutes, seconds as
integers. For hours are zero
to < 24 however switch when hours are greater than 24 print
on newline
“25error” switch when hours are thirteen break switches otherwise
by default
print on new line “top of the hour!” , For minutes are zero to 60,
For seconds
are zero to 60 in this loop print on a line hours value separated
by a colon
character minutes value separated by a colon character seconds
value with
new line character. Just before ending print on new line
“Program finished!”
then terminate program.
#include <stdio.h>
#include <time.h>
#include <unistd.h>
#include <stdlib.h>
int main()
{
int hour=0;
int min=0;
int sec=0;
while(1)
{
system("clear");
printf("%02d : %02d :
%02d \n",hour,min,sec);
fflush(stdout);
sec++;
if(sec==60){
min+=1;
sec=0;
}
if(min==60){
hour+=1;
min=0;
}
if(hour==24){
hour=0;
min=0;
sec=0;
}
if (hour>24)
{
printf("25 error");
}
if (hour == 13)
{
printf("Top of the hour!");
}
printf("Program
finished! \n");
sleep(1);
}
return 0;
}
Get Answers For Free
Most questions answered within 1 hours.