Search C Program

Loading...

Leap Year

/* Check Leap Year */
#include<stdio.h>
int main()
{
    int y;
    printf("Enter a year: ");
    scanf("%d",&y);
    if(y%4==0)
        printf("Leap Year");
    else
        printf("Not a Leap Year");
   return 0;
}

6 comments:

  1. //above pgm is correct bt not working properly for all input like 1900,1700 etc
    //below pgm is working correctly
    //check wheter leap year or not

    #include
    int main()
    {
    int year;
    printf("enter the year:\n");
    scanf("%d",&year);
    if(year%4==0&&(year%400==0||year%100!=0))
    printf("This is a leap year:");
    else
    printf("This isnot a leap year:\n");
    return 0;
    }

    ReplyDelete
    Replies
    1. he is correct

      Delete
    2. if(((year%4==0)&&(year%100!=0))||(year%400==0))
      printf("%d is a leap year",year);
      else
      printf("%d is not a leap year",year);

      Delete
    3. yup, this is precisely correct..

      Delete
    4. 1900 isn't a leap year...

      Delete
  2. #include
    main()
    {
    int year;
    printf("\nEnter the Year\n");
    scanf("%d",&year);
    if(year%400==0)
    printf("\nLEap year");
    else if(year%4==0)
    printf("\nLEap year");
    else if(year%100==0)
    printf("\nCommon YEar");
    else
    printf("\nCommon YeaR");

    }

    also works

    ReplyDelete