Friday, March 4, 2011

User-Defined Functions

In preparing the calender for a year we need to know whether that particular year is leap year or not. Design a function leap ( ) that receives the year as a parameter and returns an appropriate message. What modifications are required if we want to use the function in preparing the actual calender?

#include <stdio.h>
void leap(int year);
void main()
{
int year;
clrscr();
printf("Enter the year from 1500 to 2020\nYou can also enter last two digit\
 it will be taken as 1900's year:");
scanf("%d",&year);
leap(year);
getch();
}
void leap(int year)
{
if(year>0&&year<100)
year=year+1900;
if(year>99&&year<1500||year>2020)
printf("Wront input!");
else
if(year%4==0)
printf("This is the leap year!");
else
if(year%4!=0)
printf("This is not leap year!");
}
OUTPUT
Enter the year from 1500 to 2020
You can also enter last two digit it will be taken as 1900's year : 47
This is not leap year!

Enter the year from 1500 to 2020
You can also enter last two digit it will be taken as 1900's year : 2012
This is the leap year!

Enter the year from 1500 to 2020
You can also enter last two digit it will be taken as 1900's year : 2025
Wrong input!

No comments:

Post a Comment