Learning by doing: Reading books and trying to understand the (code) examples
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
372 B

  1. #include <stdio.h>
  2. #include <limits.h>
  3. #define SEC_PER_YEAR 3.156e7
  4. int main (void) {
  5. unsigned age;
  6. printf("Enter your age: ");
  7. scanf("%u", &age);
  8. if ((unsigned int)(UINT_MAX / SEC_PER_YEAR) < age) {
  9. printf("Integer overflow\n");
  10. return 1;
  11. } else {
  12. printf("You are %u seconds old\n", (unsigned int)(age * SEC_PER_YEAR));
  13. return 0;
  14. }
  15. }