Skip to content

Commit fd1a8ea

Browse files
committed
ReEdit NestedIfLeaptest: Fix Minor Bugs
1 parent 44be89e commit fd1a8ea

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

NestedIfLeapYear.c

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,31 @@
11
// Leap year check using nested if statements
22

33
#include<stdio.h>
4-
int main()
4+
#include<stdlib.h>
5+
void main()
56
{
67
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);
1930

2031
}

0 commit comments

Comments
 (0)