Program for updating the time by one second

0
32
#include<studio.h>
#include<conio.h>
#include<math.h>
void main()
{
  int h,m,s;
  clrscr();
  printf("Enter time h m s\n);
  scanf("%d%d%d",&h,&m,&s);
  if((h<0)||(m<0)||(s<0))   /* hour or minute or seconds can not be -ve number */
       printf("\n invalid data \n");
  else
    if((h>12)||(m>59)||(s>59))    /* the extreme boundary condition */
        printf("\n invalid time entry \n);
    else
        {
          s++;   /* increase the seconds by one */
          if(s>59)
          {
            s=0;  /* after increment when s becomes more than 59 minute
                         changes by 1 */
            m++;
           }
           if(m>59)
           {
              m=0;
              h++;
           }
           if(h>12)
                h=1;
           printf("\n time updated by one second is \n");
           printf("%4d%4d%4d",h,m,s);
          }
getch();
}
    Output 1:
    Enter time h m s  
    2 59 59 
    time updated by one second is 
    3 0 0
    Output 2:
    Enter time h m s
    -2 4 8
     invalid data
     Output 3:
     Enter time h m s
     2 59 65
     invalid time entry

 

 

 

Program for updating the time by one second Program for updating the time by one second in c language c Program for updating the time by one second Write a Program for updating the time by one second updating the time by one second Program for updating the time by 1 secondProgram for updating the time by 1 second in c 

LEAVE A REPLY

Please enter your comment!
Please enter your name here