English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Using following:
1> Divisible by 4 (since leap year is divisible by 4)
2> Not divisible by 100 (like 2900)
3> Divisible by 400 (like 2800)

Any suggestions please??

2007-07-21 04:48:27 · 5 answers · asked by neobuddy89 2 in Computers & Internet Programming & Design

5 answers

x%y is the remainder of x/y (x mod y).

(year%4==0 && year%100!=0 || year%400==0)

That says if the year is divisable by four and not divisable by one hundred, OR the year is divisable by 400. You can use that in a condidtional statement like this:

int isLeap(year)
int year;
{
return (year%4==0 && year%100!=0 || year%400==0);
}

And that's all. :D

You can call isLeap like this:

if (isLeap(2007))
printf("2007 is a leap year!");
else
printf("2007 is not a leap year!");

2007-07-21 04:57:47 · answer #1 · answered by hac 3 · 0 0

here is how I could do it (you will need to convert my psuedo code into c code of course)

enter year

input YEAR

begin case (c switch)

case mod(YEAR,4) = 0
print "is a leap year"
case mod(YEAR,100) = 0
print "is a leap year"
case mod(YEAR,400) = 0
print "is a leap year"
case default
print "not a leap year"

look up

imod
switch

and you should be able to write this program pretty easily

good luck

dougc

2007-07-21 05:06:55 · answer #2 · answered by Anonymous · 0 0

#inlude
int main(){
int year;
while(true) {
printf("\n Enter a year : ");
scanf("%d",&year);
if (year%4==0 && year%400==0 && year %100 !=0 )
printf("\nit is a leap year\n\n");

}
}

2007-07-21 05:12:56 · answer #3 · answered by iyiogrenci 6 · 0 0

incorporate #incorporate void substantial() { clrscr(); cout<<"enter the twelve months"<<"n"; int y; cin>>y; if((yp.c.one hundred==0&&yp.c.4 hundred==0)||(yp.c.one hundred!=0&&y%... cout<<"n it incredibly is a bounce twelve months"; else cout<<"n it incredibly isn't any longer a bounce twelve months"; getch(); } i think of it incredibly is gonna be properly suited... it exams if y is divisible by 4 and no be counted if it incredibly is a century twelve months no be counted if it incredibly is divisible by 4 hundred..bye

2016-09-30 10:23:28 · answer #4 · answered by mcglothlen 4 · 0 0

#include
#inlcude

// written by your_best_lucks@yahoo.com

void main(void)
{
int ye;
float re;

clrscr();
cout << "please enter year ";
cin >> ye;

re=ye % 4; // % will provide remainder

if(re==0) // re equal to zero then leap year
cout << " leap year ";
else
cout << "not leap year";

getch();
}

2007-07-21 09:10:37 · answer #5 · answered by New_Town_Karachi_Pakistan 1 · 0 0

fedest.com, questions and answers