File tree Expand file tree Collapse file tree 1 file changed +24
-13
lines changed Expand file tree Collapse file tree 1 file changed +24
-13
lines changed Original file line number Diff line number Diff line change 1
1
// Leap year check using nested if statements
2
2
3
3
#include <stdio.h>
4
- int main ()
4
+ #include <stdlib.h>
5
+ void main ()
5
6
{
6
7
int y ;
7
- printf ("Enter a year\n" );
8
- scanf ("%d" , & y );
9
- if (y %100 != 0 )
10
- if (y % 4 == 0 )
11
- printf ("%d is a leap year\n" , y );
12
- else
13
- printf ("%d is not a leap year\n" , y );
14
- if (y %400 == 0 )
15
- printf ("%d is a leap year stat1cond1\n" , y );
16
- else
17
- printf ("%d is not a leap year stat2cond2\n" , y );
18
- return 0 ;
8
+ printf ("Enter a year:" );
9
+ scanf ("%d" ,& y );
10
+ if (y %4 == 0 )
11
+ {
12
+ if (y %100 == 0 ) //In case of century
13
+ {
14
+ if (y %400 == 0 )
15
+ {
16
+ printf ("\n%d is a leap year" ,y );
17
+ exit (0 );
18
+ }
19
+ else
20
+ {
21
+ printf ("\n%d is not a leap year" ,y );
22
+ exit (0 );
23
+ }
24
+ }
25
+ else
26
+ printf ("\n%d is a leap year" ,y );
27
+ }
28
+ else
29
+ printf ("\n%d is not a leap year" ,y );
19
30
20
31
}
You can’t perform that action at this time.
0 commit comments