1
0

min_sec.c 731 B

1234567891011121314151617181920212223
  1. // min_sec.c -- converts seconds to minutes and seconds
  2. #include <stdio.h>
  3. #define SEC_PER_MIN 60 // seconds in a minute
  4. int main(void)
  5. {
  6. int sec, min, left;
  7. printf("Convert seconds to minutes and seconds!\n");
  8. printf("Enter the number of seconds (<=0 to quit):\n");
  9. scanf("%d", &sec); // read number of seconds
  10. while (sec > 0)
  11. {
  12. min = sec / SEC_PER_MIN; // truncated number of minutes
  13. left = sec % SEC_PER_MIN; // number of seconds left over
  14. printf("%d seconds is %d minutes, %d seconds.\n", sec,
  15. min, left);
  16. printf("Enter next value (<=0 to quit):\n");
  17. scanf("%d", &sec);
  18. }
  19. printf("Done!\n");
  20. return 0;
  21. }