pada kesempatan ini saya akan menjelaskan bagaimana ara membuat program kalender satu tahun dengan menggunakan dev c++. langsung saja silahkan anda buka dev c++ anda dan copy pastekan code source di bawah ini:
#include<stdio.h>
#include<conio.h>
#include<bits/stdc++.h>
#include<stdlib.h>
using namespace std;
/*A Function that returns the index of the day
of the date- day/month/year
For e.g-
Index Day
0 Sunday
1 Monday
2 Tuesday
3 Wednesday
4 Thursday
5 Friday
6 Saturday*/
int dayNumber(int day, int month, int year)
{
static int t[] = { 0, 3, 2, 5, 0, 3, 5, 1,
4, 6, 2, 4 };
year -= month < 3;
return ( year + year/4 - year/100 +
year/400 + t[month-1] + day) % 7;
}
int numberOfDays (int monthNumber, int year)
{
int pilih;
printf("\n|===================================|\n");
printf("\n|1. Januari | 7. JULI |\n");
printf("\n|2. FEBRUIARI | 8. AGUSTUS |\n");
printf("\n|3. MARET | 9. SEPTEMBER |\n");
printf("\n|4. APRIL | 10. OKTOBER |\n");
printf("\n|5. MEI | 11. NOVEMBER |\n");
printf("\n|6. JUNI | 12. DESEMBER |\n");
printf("\n|===================================|\n");
printf("\n\nsilahkan pilih bulan:");
scanf("%d",&pilih);
system("cls");
printf("\n=============================================\n");
switch (pilih){
// January
case 1:
printf("\n\n\t\tjanuari\n");
printf("-------------------------------------\n");
return (31);
system("cls");
break;
// February
case 2:
printf("\nfebruari\n\n");
printf("-------------------------------------\n");
if (year % 400 == 0 ||
(year % 4 == 0 && year % 100 != 0))
return (29);
else
return (28);
system("cls");
break;
// March
case 3:
printf("\nMaret\n");
printf("-------------------------------------\n");
return (31);
system("cls");
break;
// April
case 4:
printf("\nApril\n");
printf("-------------------------------------\n");
return (30);
system("cls");
// May
case 5:
printf("\nmei\n");
printf("-------------------------------------\n");
return (31);
system("cls");
// June
case 6:
printf("\njuni\n");
printf("-------------------------------------\n");
return (30);
system("cls");
// July
case 7:
printf("\njuli\n");
printf("-------------------------------------\n");
return (31);
system("cls");
// August
case 8:
printf("\nAgustus\n");
printf("-------------------------------------\n");
return (31);
system("cls");
// September
case 9:
printf("\nSeptember\n");
printf("-------------------------------------\n");
return (30);
system("cls");
// October
case 10:
printf("\nOktober\n");
printf("-------------------------------------\n");
return (31);
system("cls");
// November
case 11:
printf("\nNovember\n");
printf("-------------------------------------\n");
return (30);
system("cls");
// December
case 12:
printf("\nDesember\n");
printf("-------------------------------------\n");
return (31);}
system("cls");
}
void printCalendar(int year)
{ printf("\n======================================\n");
printf (" Calendar - %d\n\n", year);
printf("=======================================\n\n\n");
int days;
int current = dayNumber (1, 1, year);
for (int i = 0; i < 12; i++)
{
days = numberOfDays (i, year);
printf(" Sun Mon Tue Wed Thu Fri Sat\n");
system("cls");
int k;
for (k = 0; k < current; k++)
printf(" ");
for (int j = 1; j <= days; j++)
{
printf("%5d", j);
if (++k > 6)
{
k = 0;
printf("\n");
}
}
if (k)
printf("\n\n");
current = k;
}
return;
}
int main()
{
int year = 2020;
printCalendar(year);
return (0);
}
hasilnya akan seperti di bawah ini: