Professional Documents
Culture Documents
0 Flow Chart
1
2.0 Table List of Variable
2
4.0 Table List of Function
3
5.0 Program Body
#include <stdio.h>
void IslamicConvert(int d)
{
int month,day,year;
if (d <= IslamicEpoch)
{ // Date is pre-Islamic
month = 0;
day = 0;
4
year = 0;
}
else {
// Search forward year by year from approximate year
year = (d - IslamicEpoch) / 355;
while (d >= IslamicDate(1,1,year+1))
year++;
// Search forward month by month from Muharram
month = 1;
while (d > IslamicDate(month, dayH(month,year), year))
month++;
day = d - IslamicDate(month,1,year) + 1;
}
printf("\nDate In Hijrah:");
printf("\n%d / %d / %d\n\n",day,month,year);
}
void converterM2H()
{
unsigned int y,m,d,a;
//get the value for day month adn year to convert
printf("Year: "); scanf("%4u",&y);
printf("Month: "); scanf("%2u",&m);
printf("Day: "); scanf("%2u",&d);
a = GregorianCal(y,m,d);
IslamicConvert(a);
}
The next function dayM() is used to get day number in Masehi Calendar, so we can print the
date on the correct position.
5
The next command to determine if input of the user is a leap year which is the number if
days in February is changed to 29. In Masehi Calendar, if you take a period of four hundred
years, there are 303 normal years and 97 leap years. To determine which leap years, some
calculation must be perform. If a year is divisible by 4, then it is a leap year. But if that year is
divisible by 100, then it is not a leap year. However, if the year is also divisible by 400, then it
is a leap year. So we can construct the following statement:
The next function dayH() is used to get day number in Hijrah Calendar, so we can print the
date on the correct position.
6
The next command is for leap years calculation in Hijrah Calendars according to
Kuwaiti Algorithm behaviour as follows :
Common (non-leap) years have 354 days. Leap years have 355 days.
Odd-numbered months of the year have 30 days. Even-numbered months have 29 days.
Exception: the 12th month of a leap year has 30 days.
Eleven of every thirty years are leap years. The leap years are the years which are
congruent modulo 30 to any of these numbers: 2, 5, 7, 10, 13, 15, 18, 21, 24, 26, 29.
Thus, a 30-year cycle always lasts exactly (354×30)+11 = 10631 days.
The next command is the subfunction of Masehi Calendar. It is constructed for the
calling of subfucntion in the main function before the calendar can be display.
int Gregorian()
{
long unsigned int t;
unsigned int y,y1,m,m1,d,da,i,j,k;
char a[12][20]={"January","February","March","April","May",
"June","July","August","September","October","November","December"};
7
if (y<2011 || y>2020) // limit tahun
{
printf("Invalid input: 2011 selected\n");
y=2011;
}
printf("\nCalendar\n");
printf("\nYear: %u\n",y);
for(m=1;m<=12;m++)
{
y1=0;
t=0;
while(y1<y)
{
if((y1%100!=0 && y1%4==0) || y1%400==0)
{
t=t+366;
}
else
{
t=t+365;
}
y1++;
m1=1;
while(m1<m)
{
d=dayM(m1,y);
t=t+d;
m1++;
}
d=t%7;
printf("Month: %s\n",a[m-1]);
printf("%6s%6s%6s%6s%6s%6s%6s\n","Sun","Mon","Tue","Wed","Thu","Fri"
,"Sat");
k=1;
8
//Command for start printing the days
for(i=1;i<=dayM(m,y);i++,k++)
{
if(i==1)
{
if(d==0)
{
for(j=1;j<7;j++,k++)
{
printf("%6s","");
}
}
else
{
for(j=1;j<d;j++,k++)
{
printf("%6s","");
}
}
}
printf("%6d",i);
if(k%7==0)
{
printf("\n");
}
}
printf("\n\n");
}
return 0;
}
The next command is the subfunction of Hijrah Calendar. It is constructed for the
calling of subfucntion in the main function before the calendar can be display.
int hijrah()
{
long unsigned int t;
unsigned int h,h1,n,n1,d,da,i,j,k;
9
{
printf("Invalid input:1 selected\n");
h=1;
}
printf("Calendar\n");
printf("Year: %u\n",h);
for(n=1;n<=12;n++)
{
h1=0;
t=0;
while(h1<h)
{
if((((11 * h1) + 14) % 30) < 11)
{
t=t+355;
}
else
{
t=t+354;
}
h1++;
}
n1=1;
while(n1<n)
{
d=dayH(n1,h);
t=t+d;
n1++;
}
d=t%7;
printf("Month: %s\n",b[n-1]);
printf("%6s%6s%6s%6s%6s%6s%6s\n","Sun","Mon","Tue","Wed","Thu","Fri"
,"Sat");
k=1;
for(i=1;i<=dayH(n,h);i++,k++)
{
if(i==1)
{
if(d==0)
{
for(j=1;j<7;j++,k++)
{
printf("%6s","");
}
}
else
{
for(j=1;j<d;j++,k++)
{
printf("%6s","");
10
}
}
}
printf("%6d",i);
if(k%7==0)
{
printf("\n");
}
}
printf("\n\n");
}
}
int main()
{
int menu=1,a;
while (menu==1)
{
printf("\nEnter Selection : \n");
printf("\n1.Gregorian Calendar");
printf("\n2.Hijrah Calender");
printf("\n3.exit");
printf("\n\nSelected number : ");
scanf("%d",&a);
//Command for continuing Hijrah or Masehi calendar after viewing the date
if (a==1)
{
a = 1;
while (a==1)
{
gregorian(); //funtion that call subfuction to
calculate gregorian year
printf("\n\nChoose : ");
printf("\n1.Continue Gregorian");
printf("\n2.Quit Gregorian & Enter Menu");
//finish with gregorian then go to menu
11
printf("\n\nSelected number :");
scanf("%d",&a);
}
}
else if(a==3)
{
converterM2H(); // call function converter
}
else if(a==4)
{
menu = 0; //terminate this program
}
else
{
printf("Invalid input"); // if user enter wrong input
}
}
}
12
References
a. Internet Sources
1. Wikipedia
http://en.wikipedia.org/wiki/C_variable_types_and_declarations
http://en.wikipedia.org/wiki/Hijra_(Islam)
http://en.wikipedia.org/wiki/Islamic_calendar
http://en.wikipedia.org/wiki/Kuwaiti_algorithm
2. Happy Coding
http://www.c.happycodings.com/Beginners_Lab_Assignments/code11.html
b. Books
13