-
a little confuse o_0???
A year is a leap year if it is divisible by 4,however, if a year is divisible by 100, it must be divisible by 400 for it to be a leap year. Hence, 2000 is a leap year, but 1900 is not. Make a program that will input a value for year (int) and output whether it is a "Leap Year" or "Not a Leap Year".
i'm a little confused about the logic about this T_T
please someone can help me with these???
thanks in advance
-
http://en.wikipedia.org/wiki/Leap_year#Algorithm
Convert that to C/C++ code and post it here if it gives you trouble.
gg
-
waaaaaaaaaaa....
i still can't get it to work >_<
i cant understand modulo T_T
thnx a lot dude
-
-
if year modulo 400 is 0 then leap
else if year modulo 100 is 0 then no_leap
else if year modulo 4 is 0 then leap
else no_leap
-
if ((year modulo 4 is 0) and (year modulo 100 is not 0)) or (year modulo 400 is 0)
then leap
else no_leap
[edit] Leap day
-
http://en.wikipedia.org/wiki/Modulo_operation
As you can see in the table there, the C/C++ modulo operator is %
gg
-
Yes, so how would you make that into C++ code?
--
Mats
-
yeah i agree
im a newbie
so i cant really understand how to make it in C++ code
for example
the modulo of 4??
how would you encode it in C++ ?
please codeplug a little bit of understanding here
please please....
-
I would recommend a tutorial to get you up to speed on the basics on the language. Once you know the basics, converting the logic in post #5 is a breeze.
http://www.cprogramming.com/tutorial.html#c++tutorial
gg
-
-
main()
{ int year;
clrscr();
p("Enter a year: ");
s("%d",&year);
if(year%4==0 && year%100==0 && year%400)
p("The year %d is a leap year.",year);
else
p("The year %d is not a leap year.",year);
i can't get the 1900 as not a leap year T_T
still having problems with it huhuhu
-
Compare your own post #5 with what you have actually implemented in your C-code.
And a word of advice: Don't "make your own language" - printf() is a stanard function, don't use #define p printf and #define s scanf - it's just so much harder to read.
--
Mats
-
This being the C++ forum, consider using cout and cin instead . . . or post your thread in the C forum next time.
Use code tags: [code] Code here [/code]
And try to post complete code.
Oh, and main() should return int. The implicit-int rule is deprecated.
Code:
int main() {
/* ... */
return 0;
}
-
hehehehe
sorry for that dude....
i just made that here since it is easy to write
T_T
thnx to all who replied....