Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gürcan Güleç
/
iag0581
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
2
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
dbf4614e
authored
Oct 20, 2016
by
Gürcan Güleç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Deleting some mistakenly uploaded files and putting calendar.c to the right folder
parent
383bfe21
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
0 deletions
labs/lab4/calendar.c
labs/lab4/calendar.c
0 → 100644
View file @
dbf4614e
/**
* File: calendar.c
* Author Gurcan Gulec
* Created: 19 October 2016
* Last Edit: 20 October 2016
*
* Description: Gregorian calendar thing.
*
*/
#include <stdio.h>
#include <math.h>
int
main
()
{
int
date
;
int
leap
=
0
;
int
m1
[
7
]
=
{
1
,
3
,
5
,
7
,
8
,
10
,
12
};
scanf
(
"%d"
,
&
date
);
// finding the year
int
year
=
date
%
10000
;
// finding the month
int
month
=
((
date
%
1000000
)
-
year
)
/
10000
;
// finding the day
int
day
=
((
date
%
100000000
)
-
month
*
10000
-
year
)
/
1000000
;
printf
(
"Day = %d
\n
"
,
day
);
printf
(
"Month = %d
\n
"
,
month
);
printf
(
"Year = %d
\n
"
,
year
);
// month cannot be bigger than 12
if
(
month
>
12
)
{
printf
(
"Date not valid
\n
"
);
return
0
;
}
// checking the months that has 31 days and 30 days and decide if it is valid
for
(
int
a
=
0
;
a
<
7
;
a
++
)
{
if
(
month
==
m1
[
a
])
{
if
(
day
>
31
)
{
printf
(
"Date not valid
\n
"
);
return
0
;
}
}
else
{
if
(
day
>
30
)
{
printf
(
"Date not valid
\n
"
);
return
0
;
}
}
}
// deciding leap years
if
(
year
%
100
==
0
)
{
if
(
year
%
400
==
0
)
{
leap
=
1
;
}
else
{
leap
=
0
;
}
}
else
{
if
(
year
%
4
==
0
)
{
leap
=
1
;
}
else
{
leap
=
0
;
}
}
// checking february
if
(
month
==
2
)
{
if
(
leap
==
1
)
{
if
(
day
!=
29
)
{
printf
(
"Date not valid
\n
"
);
return
0
;
}
}
else
{
if
(
day
!=
28
)
{
printf
(
"Date not valid
\n
"
);
return
0
;
}
}
}
printf
(
"Date is valid
\n
"
);
return
0
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment