any year is input through the keyboard. write a program to determine wheter it’s a leap year or not?

- Using modulus operator.
- Using && amd || operators.

any year is input through the keyboard. write a program to determine wheter it’s a leap year or not?

- Using modulus operator.
- Using && amd || operators.

@rahul_kasana It looks like you are trying to get us to do your homework for you. This is a simple code but you will never learn to code if we keep doing your homework for you. I will give you the algorithm you need to follow. You can code it up yourself. If you have any problems, we can help you in debugging.

Algorithm:

To determine whether a year is a leap year, follow these steps:

```
1) If the year is evenly divisible by 4, go to step 2. Otherwise, go to step 5.
2) If the year is evenly divisible by 100, go to step 3. Otherwise, go to step 4.
3) If the year is evenly divisible by 400, go to step 4. Otherwise, go to step 5.
4) The year is a leap year (it has 366 days).
5) The year is not a leap year (it has 365 days).
```

2 Likes

in college we dont get homework im new to coding so doesn’t know how to use modulus operator just this. btw thanks for the help.

but how will it determine if year has 365 or 366 days just from the year entered? im mean how can it determine from year1966 whether it has 365 days or 366

Very nice answer

…we assume you are interested in Gregorian calendar - http://en.wikipedia.org/wiki/Leap_year#Gregorian_calendar

Modulus operator in this case is a transformation of

```
year is evenly divisible by 4
```

to condition in code

`if ( year%4 == 0 )`

The modulo operator gives the remainder of the division. So say you want to check a number(num) is even or not. Number is even if remainder on division by 2 is zero. So get the remainder rem = num 2. Now if rem==0 then number is even else it is odd. Similarly for remainder with 4 you can do rem = num 4 and for remainder with 400 you can do rem = num 400. With this and a basic understanding of if-else statement you should try to implement the algorithm given above.

#include<stdio.h>

#include<conio.h>

void main()

{int a;

printf(“enter the year of your choice\n”);

scanf("%d",&a);

if(a%4==0)

printf("%d is a leap year\n",a);

else

printf("%d is NOT a leap year\n");

getch();

}