Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- typedef struct{
- int h,m,s;
- }Clock;
- void startClock(Clock *clock){
- clock->h = 0;
- clock->m = 0;
- clock->s = 0;
- }
- void incClock(Clock *clock){
- clock->s ++;
- if (clock->s>=60){
- clock->s = 0;
- clock->m ++;
- if (clock->m>=60){
- clock->m = 0;
- clock->h ++;
- if (clock->h>12){
- clock->h = 1;
- }
- }
- }
- }
- void decClock(Clock *clock){
- clock->s --;
- if (clock->s<0){
- clock->s = 59;
- clock->m --;
- if (clock->m<0){
- clock->m = 59;
- clock->h --;
- if (clock->h<=0){
- clock->h = 12;
- }
- }
- }
- }
- int getSecs(Clock *clock){
- return clock->s + clock->m*60 + clock->h*3600;
- }
- int main(){
- Clock clock1;
- Clock clock2;
- startClock(&clock1);
- startClock(&clock2);
- int i,count=0;
- for (i=0;i<60*60*24;i++){
- if (getSecs(&clock1) == getSecs(&clock2)){
- count++;
- }
- incClock(&clock1);
- decClock(&clock2);
- }
- printf("Count : %d\n",count);
- return 0;
- }
Add Comment
Please, Sign In to add comment