Pages

Rabu, 13 April 2011

Program C + +: Creating a Simple Calendar

Algorithm: we fed the year and month codes [1 ... 12]
if the year is a leap year (the year runs out at the 4 or 400 and not go on for 100), and code-month = 2 (February), then there is 29 days if not then there is 28 days
if code in there 31 days 1,3,5,7,8,10,12
if the code months 4, 6.9 then there is 30 days
if not months of code between the number [1 ... 12), then one month code
# Include <iostream> # Include <conio.h>
int main () { int year, month, bil;
court <<"enter the year:"; cin>> year; court <<"Enter month [1 ... 12]:"; cin>> month;
switch (month) { case 2: if ((year% 100 == 0) | | (year% 100! = 0) & & (year% 400 == 0)) { for (int i = 1; i <= 29; i + +) { court <<i <<""; } } else { for (int i = 1; i <= 28; i + +) { court <<i <<""; } } break; case 1: case 3: case 5: case 7: case 8: case 10: case 12: { for (int i = 1; i <= 31; i + +) { court <<i <<""; } } break;
case 4: case 6: case 9: { for (int i = 1; i <= 30; i + +) { court <<i <<""; } } break; default: court <<"wrong code in \ n"; } getch ();

0 komentar:

Posting Komentar