Extra 5% OFF Use Code: OL05
Free Shipping over ₹999

Digital clock

#include<stdio.h>

// create a function for second
void one_second()
{
    
    long i,j,counter;
    for(i = 0; i < 20000; i++)
    {
        for(j = 0; j < 20000; j++)
        {
            //incement counter variable for creating a second 
            counter++;
        }
    }
}
int main()
{
    //input hour,minute and second 
    int second=0,minute=0,hour=0;
    printf("Enter hour:");
    scanf("%d",&hour);
    printf("Enter minute:");
    scanf("%d",&minute);
    printf("Enter second:");
    scanf("%d",&second);
    while(1)
    {
        // calling one_second function 
        one_second();
        second++;
        if(second==60)
        {
            minute+=1;
            second=0;
        }
        if(minute==60)
        {
            hour+=1;
            minute=0;
        }
        if(hour==24)
        {
            hour=0;
            minute=0;
        }
        printf("\n%d:%d:%d",hour,minute,second);
        
    }
    
}

    Leave a Reply

    Your email address will not be published.

    Need Help?