fork download
  1. /* leap-year */
  2.  
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5.  
  6. int isLeap(int year) {
  7. if (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0))
  8. return 1;
  9. else
  10. return 0;
  11. }
  12.  
  13. int main(void) {
  14. int year;
  15. printf("Enter a year:\n");
  16. if ( scanf("%d", &year) != 1
  17. || year <= 0)
  18. {
  19. printf ( "invalid year.\n" );
  20. return EXIT_FAILURE;
  21. }
  22. printf("year %d ", year);
  23. if (isLeap(year))
  24. printf("is a leap year\n");
  25. else
  26. printf("is not a leap year\n");
  27. return EXIT_SUCCESS;
  28. }
  29.  
Success #stdin #stdout 0.01s 5288KB
stdin
2041
stdout
Enter a year:
year 2041 is not a leap year