Practice Program
Solution:
int is_leapyear(int year)
{
if(year % 4 == 0) //if year is divisible by 4 and
if(year % 100 !=0) //not divisible by 100
return 1; //then year is a leap year.
else
if(year % 400==0)//if year is divisible by 100 but
return 1;//it is divisible by 400 then
//year is leap year.
return 0;
}
int is_leapyear(int year) { if(year % 4 == 0) //if year is divisible by 4 and if(year % 100 !=0) //not divisible by 100 return 1; //then year is a leap year. else if(year % 400==0)//if year is divisible by 100 but return 1;//it is divisible by 400 then //year is leap year. return 0; }
Using above function:
void main()
{ //maximum among two numbers.
int result;
//calling function is_leap_year
result = is_leapyear(2012);
if(result == 1) //if return value is 1
printf("It is a leap year.");//then we will print it is
else //leap year.
printf("It is a leap year.");//otherwise we will print
//it is no leap year.
}
void main() { //maximum among two numbers. int result; //calling function is_leap_year result = is_leapyear(2012); if(result == 1) //if return value is 1 printf("It is a leap year.");//then we will print it is else //leap year. printf("It is a leap year.");//otherwise we will print //it is no leap year. }
Output1
It is a leap year.
Using above function:
void main()
{ //maximum among two numbers.
int result;
//calling function is_leap_year
result = is_leapyear(1990);
if(result == 1) //if return value is 1
printf("It is a leap year.");//then we will print it is
else //leap year.
printf("It is not a leap year.");//otherwise we will print
//it is no leap year.
}
void main() { //maximum among two numbers. int result; //calling function is_leap_year result = is_leapyear(1990); if(result == 1) //if return value is 1 printf("It is a leap year.");//then we will print it is else //leap year. printf("It is not a leap year.");//otherwise we will print //it is no leap year. }
Output2
It is not a leap year.
Using above function:
void main()
{ //maximum among two numbers.
int result;
//calling function is_leap_year
result = is_leapyear(2014);
if(result == 1) //if return value is 1
printf("It is a leap year.");//then we will print it is
else //leap year.
printf("It is not a leap year.");//otherwise we will print
//it is no leap year.
}
void main() { //maximum among two numbers. int result; //calling function is_leap_year result = is_leapyear(2014); if(result == 1) //if return value is 1 printf("It is a leap year.");//then we will print it is else //leap year. printf("It is not a leap year.");//otherwise we will print //it is no leap year. }
Output3
It is not a leap year.
0 Comments
Post a Comment