ACP2_7

#include <stdio.h> void main() { struct time{ int s,m,h; }t1,t2,dit; int a; clrscr(); printf("\nEnter time (hh-mm-ss) :\n"); flushall(); scanf("%d",&t1.h); flushall(); scanf("%d",&t1.m); flushall(); scanf("%d",&t1.s); printf("\nEnter time to subtract (hh-mm-ss) :\n"); flushall(); scanf("%d",&t2.h); flushall(); scanf("%d",&t2.m); flushall(); scanf("%d",&t2.s); if(t1.h<1||t1.h>24||t2.h<1||t2.h>24) { printf("\nInvalid Input!"); getch(); exit(); } if(t1.m<1||t1.m>60||t2.m<1||t2.m>60) { printf("\nInvalid Input!"); getch(); exit(); } if(t1.s<1||t1.s>60||t2.s<1||t2.s>60) { printf("\nInvalid Input!"); getch(); exit(); } if(t1.h>=t2.h) dit.h=t1.h-t2.h; else { printf("\nTime 1 less than time 2."); getch(); exit(); } if(t1.h==t2.h && t2.m>t1.m) { printf("\nTime 1 less than time 2."); getch(); exit(); } if(t1.m>=t2.m) dit.m=t1.m-t2.m; else { dit.m=t2.m-t1.m; dit.m=60-dit.m; dit.h--; } if(t1.h==t2.h && t1.m==t2.m && t2.s>t1.s) { printf("\nTime 1 less than time 2."); getch(); exit(); } if(t1.s>=t2.s) { dit.s=t1.s-t2.s; } else { dit.s=t2.s-t1.s; dit.s=60-dit.s; dit.m--; } printf("\nDifference : %d hours, %d mins & %d secs",dit.h,dit.m,dit.s); getch(); }

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.