code of the stopwatch using c language
#include <stdio.h>
#include <windows.h> // this is for sleep function we are going to use it in furture code
int main()
{
int h , m ,s ; // create variable for hour minutes and second
int d = 1000; // this will use in loop for milliseconds
printf("Set time : \n");
scanf("%d%d%d",&h,&m,&s);
if(h>12 || m > 59 || s > 59){
printf("Error ! \n");
exit(0);
}
// now create a loop while loop
while(1) // this will generate infine loop
{
s++; // second will be increament infinitly
if(s>59){
m++;
s=0;
}
if(m>59){
h++;
m = 0;
}
if(h>12){
h = 1;
}
// now prinf some text to decorate coding or hints
printf("Clock time : \n");
printf("%02d : %02d : %02d" , h, m , s);
Sleep(d); // this is the function that we discussed before above code
system("cls");
}
}
// now run the code
// you can find this code in the description of this video
No comments:
Post a Comment