You are on page 1of 13

1.

0 Flow Chart

1
2.0 Table List of Variable

No. Type of Variable Variable


1. int a
2. int dayM
3. int menu=1
4. int d
5. int dayH
6. int m2,y2
7. int m1,y
8. long unsigned int t
9. unsigned int y,y1,m,m1,d,da,i,j,k
10. char a
11. char b
12. unsigned int h,h1,n,n1,

3.0 Table List of Subfunction

No. Subfunction Type of Variable Variable Note


1. void IslamicConvert int d
intdayM (int m1, int
2. int m1,y1
y1);
intIslamicDate(int m,
3. int m,d,y To convert to
int d, int y);
Islamic day
intdayH (int m2, int
4. int m2,y2
y2);
intGregorianCal(int
5. Int y,m,d
y, int m, int d)

2
4.0 Table List of Function

No. Function Input Output

1. Display Choice printf -

2. Read Choice scanf int a

3. Enter Year ,Month,Date printf -

4. Display Calendar - printf

5. Select Number Scanf int a

3
5.0 Program Body

#include <stdio.h>

int dayM (int m1, int y1);


int IslamicDate(int m, int d, int y);
int dayH (int m2, int y2);

The next command is to convert a Masihi date to Hijrah date.

//Command for converter from Masihi date to Hijrah date

int GregorianCal(int y, int m, int d)


{
int year = y;
int month = m;
int day = d;

int N = day; // days this month


for (m = month - 1; m > 0; m--)//days in prior months this year
N = N + dayM(m, year);
return
(N // days this year
+ 365 * (year - 1) // days in previous years ignoring leap
days
+ (year - 1)/4 // leap days before this year
- (year - 1)/100 // minus prior century years
+ (year - 1)/400); // plus prior years divisible by 400
}

const int IslamicEpoch = 227014;

int IslamicDate(int m, int d, int y)


{
int year=y;
int month=m;
int day=d;

return (day // days so far this month


+ 29 * (month - 1) // days so far
+ month/2 // this year
+ 354 * (year - 1) // non-leap days in prior years
+ (3 + (11 * year)) / 30 // leap days in prior years
+ IslamicEpoch);
}

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);
}

//End of converter command

The next function dayM() is used to get day number in Masehi Calendar, so we can print the
date on the correct position.

//Command for determining days in Masehi Calendar

int dayM (int m1, int y1)


{
int d;
if(m1==1 || m1==3 || m1==5 || m1==7 || m1==8 || m1==10 || m1==12
)
{
d=31;
}
else if(m1==4 || m1==6 || m1==9 || m1==11)
{
d=30;
}

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:

//Command for Leap Year of Masihi Calendar

else if ((y1%100!=0 && y1%4==0) || y1%400==0)


{
d=29;
}
else
{
d=28;
}
return d;
}

The next function dayH() is used to get day number in Hijrah Calendar, so we can print the
date on the correct position.

//Command for determining days in Hijrah Calendar

int dayH (int m2, int y2)


{
int d;
if(m2==1 || m2==3 || m2==5 || m2==7 || m2==9 || m2==11 )
{
d=30;
}
else if(m2==2 || m2==4 || m2==6 || m2==8 || m2==10)
{
d=29;
}

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.

//Command for Leap Year Calculation in Hijrah Calendar according to Kuwaiti


Algorithm

else if ((((11 * y2) + 14) % 30) < 11)


{
d=30;
}
else
{
d=29;
}
return d;
}

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.

//Subfunction for Masehi Calendar

int Gregorian()
{
long unsigned int t;
unsigned int y,y1,m,m1,d,da,i,j,k;

//Array for storing the name of Months in Masehi calendar

char a[12][20]={"January","February","March","April","May",

"June","July","August","September","October","November","December"};

printf("Enter the year: ");


scanf("%4u",&y);

// %4u placeholder is space provided for unsigned 4 value

7
if (y<2011 || y>2020) // limit tahun
{
printf("Invalid input: 2011 selected\n");
y=2011;
}

//Command for start to print the calendar

printf("\nCalendar\n");
printf("\nYear: %u\n",y);
for(m=1;m<=12;m++)
{
y1=0;
t=0;

//Command to check the days in years

while(y1<y)
{
if((y1%100!=0 && y1%4==0) || y1%400==0)
{
t=t+366;
}
else
{
t=t+365;
}
y1++;

//Command to check the days in Month

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.

//Subfunction for Hijrah

int hijrah()
{
long unsigned int t;
unsigned int h,h1,n,n1,d,da,i,j,k;

char b[12][20]={"Muharram","Safar","Rabi al-Awwal","Rabi ai-


Akhir", "Jumada al-Ula",
"Jumada al-Akhira","Rajab","Sha'ban","Ramadan","Shawwal","Dhu
al-Qa'da","Dhu al-Hijja"};

printf("Enter the year: ");


scanf("%4u",&h);
if (h<0)

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

printf("\n\nSelected number :");


scanf("%d",&a);
}
}
else if(a==2)
{
a = 1;
while (a==1)
{
hijrah();
printf("\n\nChoose : ");
printf("\n1.Continue Hijrah");
printf("\n2.Quit Hijrah & Enter Menu");
//finish with hijrah 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

1. Computer Science : A Structured Programming Approach Using C 2nd Edition


Publisher : Brooks/Cole
Writer : B.A Forouzan and R.F Gilberg

13

You might also like