Saturday, November 10, 2012

User Define Function- LeapYear

Q. Write a C program to find entered year is leap year or not using own created function say "leap".

Ans.

/*c program for find year is leap year or not using user define function leap*/
#include<stdio.h>
int leap(int );
int main()
{

 int year;
 printf("Enter any year : ");
 scanf("%d", &year);
 if(leap(year))
   printf("\n%d is leap year",year);
 else
   printf("\n%d is not leap year",year);
 return 0;
}

int leap(int y)
{
 if((y%400==0 && y%100==0)||(y%4==0))
    return 1;
 else
    return 0;
}

The output of above program would be:


Output of check year is leap year or not using user define function C program
Figure: Screenshot for user define function to
check year is leap year C program



Output of check year is leap year or not using user define function C program
Figure: Screenshot for user define function to 
check year is not leap year C program


No comments:

Post a Comment