Computer Science, asked by saumytiwarI, 11 months ago

Write a simple c language program for a 10 second countdown/timer

Answers

Answered by rockgourab1985
1

Answer:

set the variable count_down_time_in_secs in seconds for desired count down time.

The Code is self explanatory.

1 minute = 60 secs

5 minutes = 60x5 secs

30 minutes =60x30 secs

1 hour = 60x60 secs

Hide   Shrink    Copy Code

#include <stdio.h>

#include <time.h>

 

int main ()

{

 

 

unsigned int x_hours=0;

unsigned int x_minutes=0;

unsigned int x_seconds=0;

unsigned int x_milliseconds=0;

unsigned int totaltime=0,count_down_time_in_secs=0,time_left=0;

clock_t x_startTime,x_countTime;

count_down_time_in_secs=10;  // 1 minute is 60, 1 hour is 3600

 

   x_startTime=clock();  // start clock

   time_left=count_down_time_in_secs-x_seconds;   // update timer

while (time_left>0)  

{

 x_countTime=clock(); // update timer difference

 x_milliseconds=x_countTime-x_startTime;

 x_seconds=(x_milliseconds/(CLOCKS_PER_SEC))-(x_minutes*60);

 x_minutes=(x_milliseconds/(CLOCKS_PER_SEC))/60;

 x_hours=x_minutes/60;

 

 time_left=count_down_time_in_secs-x_seconds; // subtract to get difference  

 printf( "\nYou have %d seconds left ( %d ) count down timer by TopCoder  

",time_left,count_down_time_in_secs);

}

printf( "\n\n\nTime's out\n\n\n");

return 0;

}

.

.

.

TopCoder

                                                       or

set the variable count_down_time_in_secs in seconds for desired count down time.The Code is self explanatory.1 minute = 60 secs5 minutes = 60x5 secs30 minutes =60x30 secs1 hour = 60x60 secs#include #include int main (){ unsigned int...

Explanation:

Similar questions