C examples for Operator:Arithmetic Operator
Use the modulus operator to convert a large number of seconds into hours, minutes, and seconds.
#include <stdio.h> #define SECS_PER_MIN 60/* ww w. j a v a 2 s . com*/ #define SECS_PER_HOUR 3600 unsigned seconds, minutes, hours, secs_left, mins_left; int main( void ) { seconds = 30000; hours = seconds / SECS_PER_HOUR; minutes = seconds / SECS_PER_MIN; mins_left = minutes % SECS_PER_MIN; secs_left = seconds % SECS_PER_MIN; printf("%u seconds is equal to ", seconds); printf("%u h, %u m, and %u s\n", hours, mins_left, secs_left); return 0; }