Thursday, March 15, 2012

Time in Seconds

Function calculateSeconds() below take the time as three integer argument (hours, minutes, and seconds) and returns the number of seconds since the last time the clock "struct 12".
/*
   title: timeInSecond
   author: aeriqusyairi
   date: jan24 2012
*/
#include<stdio.h>

unsigned calculateSecond(int, int, int);

int main(){
   int h = 0, m = 0, s = 0, seconds = 0;
   
   printf("Enter time in hour, minute, and second...\nHour: ");
   scanf("%d", &h);
   printf("Minutes: ");
   scanf("%d", &m);
   printf("Seconds: ");
   scanf("%d", &s);
   
   printf("The number of seconds since the last time the clock struck 12 is %u\n", calculateSecond(h, m, s));
   
   system("pause");
   return 0;
}

unsigned calculateSecond(int hours, int minutes, int seconds){   
   return (hours * 3600) + (minutes * 60) + seconds;         
}

No comments:

Post a Comment