- If the year is divisible by 100, then the year should also divisible by 400
Following algorithm:
1. Enter the (year)
2. If the rest of the division (the year divided by 4)! = (not equal to) 0, then print ("Year", the year, "not a leap year")
Otherwise
3. If the rest of the division (the year divided by 100) = (equal to) 0 and the rest of the division (the year divided by 400)! = (not equal to) 0, then print ("Year", the year, "not a leap year)
otherwise
4. If it does not meet all the conditions above, print ("Year", the year, "is a leap year")
Following implementation of the program:
01 #include <cstdlib>
02 #include <iostream>
03
04 using namespace std;
05
06 int main(int argc, char *argv[])
07 {
08 int tahun;
09 cout<<"Masukan tahun : ";
10 cin>>tahun;
11 cout<<endl;
12 if(tahun%4!=0)
13 cout<<"Tahun "<<tahun<<" Bukan tahun kabisat\n\n";
14 else if((tahun%100==0)&&(tahun%400!=0))
15 cout<<"Tahun "<<tahun<<" Bukan tahun Kabisat\n\n";
16 else
17 cout<<"Tahun "<<tahun<<" Adalah tahun kabisat\n\n";
18
19 system("PAUSE");
20 return EXIT_SUCCESS;
21 }
Following algorithm:
1. Enter the (year)
2. If the rest of the division (the year divided by 4)! = (not equal to) 0, then print ("Year", the year, "not a leap year")
Otherwise
3. If the rest of the division (the year divided by 100) = (equal to) 0 and the rest of the division (the year divided by 400)! = (not equal to) 0, then print ("Year", the year, "not a leap year)
otherwise
4. If it does not meet all the conditions above, print ("Year", the year, "is a leap year")
Following implementation of the program:
01 #include <cstdlib>
02 #include <iostream>
03
04 using namespace std;
05
06 int main(int argc, char *argv[])
07 {
08 int tahun;
09 cout<<"Masukan tahun : ";
10 cin>>tahun;
11 cout<<endl;
12 if(tahun%4!=0)
13 cout<<"Tahun "<<tahun<<" Bukan tahun kabisat\n\n";
14 else if((tahun%100==0)&&(tahun%400!=0))
15 cout<<"Tahun "<<tahun<<" Bukan tahun Kabisat\n\n";
16 else
17 cout<<"Tahun "<<tahun<<" Adalah tahun kabisat\n\n";
18
19 system("PAUSE");
20 return EXIT_SUCCESS;
21 }
Tidak ada komentar:
Posting Komentar