Program
/* This program checks whether the given year is a leap year or not */
#include <stdio.h> /* It's ok not to have space between include and <stdio.h> */
int main (void) /* It's ok not to have space between main and (void). You can drop void off too. */
{
int year;
printf("\nEnter the year: ");
scanf("%d",&year);
if ( (year%4 == 0 && year%100 != 0) || year%400 == 0 )
printf("\n%d is a leap year.\n\n",year);
else
printf("\n%d is not a leap year.\n\n",year);
return; /* "return ;" works too. "return 0" works too. "return (0)" works too.*/
}
Compilation, Run and Output
[sreedhar@manchu2 cprogs_work_machine]$ gcc calendar.c -o calendar
[sreedhar@manchu2 cprogs_work_machine]$ ./calendar
Enter the year: 2000
2000 is a leap year.
[sreedhar@manchu2 cprogs_work_machine]$ ./calendar
Enter the year: 2001
2001 is not a leap year.
[sreedhar@manchu2 cprogs_work_machine]$ ./calendar
Enter the year: 2004
2004 is a leap year.
[sreedhar@manchu2 cprogs_work_machine]$ ./calendar
Enter the year: 2100
2100 is not a leap year.
[sreedhar@manchu2 cprogs_work_machine]$
No comments:
Post a Comment