Monday, July 30, 2018

C program for leap year

Here,I used below C program to find whether a year is leap year or not. It's working fine.

Example#1:

#include <stdio.h>

int main()

{

  int year;

  printf("\nPlease enter a year to check whether it is a leap year or not:");

  scanf("%d", &year);



  if ( year%400 == 0)

    printf("\n%d is a leap year", year);

  else if ( year%100 == 0)

    printf("\n%d is not a leap year", year);

  else if ( year%4 == 0 )

    printf("\n%d is a leap year", year);

  else

    printf("\n%d is not a leap year", year);

  return 0;


}

Output:


Example#2:

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

Output:

No comments:

Post a Comment

C program for find square value

This is an example of how to find square value of a number using function.  #include<stdio.h> float square ( float x ); int ma...