dmilicev

leap_year_v1.c

Oct 12th, 2019
485
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.94 KB | None | 0 0
  1. /*
  2.  
  3.     Leap year v1.c
  4.  
  5.     With function leapYear()
  6.  
  7. C program to check if a given year is leap year or not:
  8.  
  9. Rule 1. Every fourth year is a leap.
  10.  
  11. Rule 2. The exception to Rule 1 is that every hundredth year is not a leap.
  12.  
  13. Rule 3. The exception to Rule 2 is that every 400th year is a leap.
  14.  
  15. */
  16.  
  17. #include <stdio.h>
  18.  
  19. // Returns 1 if year is leap, otherwise returns 0.
  20. int leapYear(int year)
  21. {
  22.     // Return true if year is a multiple of 4 and not multiple of 100.
  23.     // OR year is multiple of 400.
  24.     if (((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0))
  25.         return 1;
  26.     else
  27.         return 0;
  28. }
  29.  
  30. int main(void)
  31. {
  32.     int i, year;
  33.  
  34.     printf("\n Enter the year: ");
  35.     scanf("%d", &year);
  36.  
  37.     for(i=year-10;i<=year+10;i++)
  38.         if( leapYear(i) )
  39.             printf("\n %d. is a leapYear \n",i);
  40.         else
  41.             printf("\n %d. isn't a leapYear \n",i);
  42.  
  43.     printf("\n\n");
  44.  
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment