Reputation: 195
My program is showing "it is a leap year" for every output. Please let me know where i am committing an error??
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("\n Enter the year : ");
scanf("%d",a);
if (a%400 == 0)
printf("\n It is a leap year");
else
if (a%100 == 0)
printf("\n It is not a leap year");
else
if (a%4 == 0)
printf("\n It is a leap year");
else
printf("\n It is not a leap year");
getch();
}
Upvotes: 1
Views: 206
Reputation: 4470
Please edit your scanf line scanf("%d", a);
to scanf("%d",&a);
. You need to pass the address of a, not its value.
Upvotes: 0
Reputation: 465
You forgot a "&":
scanf("%d",&a);
so it always returns the first as true as "a" is = 0 no matter what you enter
Upvotes: 0
Reputation: 994221
The scanf()
function requires you pass the address of your variable:
scanf("%d",&a);
Upvotes: 4