PROBLEM 39:
Prompt the user for his/her year of birth and if the year is a leap year print “You were born in a leap year”, otherwise print the age of the user. (leap.c)
CODE:
#include<stdio.h>
main()
{
// Variable declaration//
int year;
int present_year=2016;
/*Input*/
printf("Enter year:");
scanf("%d",&year);
/* actual Working */
if(year%4==0)
{
printf("You were born in a leap year");
}
else if(year<=2016 && year%4!=0)
{
present_year=present_year-year;
printf("Your age is:%d",present_year);
}
else if(year>2016 || year%4!=0)
{
printf("we cannot tell you the age because its above than current year\nbut its not a leap year.");
}
return 0;
}
PROGRAM OUTPUT:
For more problems click here
No comments:
Post a Comment