Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
tranvu
/
iax583
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
10e5ccf6
authored
Sep 10, 2018
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Homework for lab 2
parent
91bf4bfc
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
88 additions
and
0 deletions
Homework Lab 2/homework_lab2.c
Homework Lab 2/homework_lab2.c
0 → 100644
View file @
10e5ccf6
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
int
isDate
(
int
input
);
int
largestNumber
();
int
smallestNumber
();
int
toBinary
(
int
input
);
int
main
()
{
// Custom changable variables ----------------------------------
int
numberToBinary
=
1023
;
int
date
=
29022100
;
// End -----------------------------------------------
printf
(
"Homework Lab 2 (10 - September - 2018)
\n
"
);
printf
(
"Largest number in array:
\t
%d"
,
largestNumber
());
printf
(
"
\n
Smallest number in array:
\t
%d"
,
smallestNumber
());
printf
(
"
\n
Is valid date:
\t\t\t
%s"
,
isDate
(
date
)
==
1
?
"True"
:
"False"
);
printf
(
"
\n
Binary Homework:
\t\t
%d"
,
toBinary
(
numberToBinary
));
return
(
EXIT_SUCCESS
);
}
int
largestNumber
()
{
int
size
=
10
;
int
numbers
[]
=
{
15
,
6
,
7
,
98
,
-
8
,
65
,
777
,
-
87
,
213
,
5
};
int
i
;
int
largest
=
numbers
[
0
];
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
numbers
[
i
]
>
largest
)
largest
=
numbers
[
i
];
}
return
largest
;
}
int
smallestNumber
()
{
int
size
=
10
;
int
numbers
[]
=
{
15
,
6
,
7
,
98
,
-
8
,
65
,
777
,
-
87
,
213
,
5
};
int
i
;
int
smallest
=
numbers
[
0
];
for
(
i
=
0
;
i
<
size
;
i
++
)
{
if
(
numbers
[
i
]
<
smallest
)
smallest
=
numbers
[
i
];
}
return
smallest
;
}
int
isDate
(
int
input
)
{
int
day
=
input
/
1000000
;
int
month
=
input
/
10000
%
100
;
int
year
=
input
%
10000
;
if
(
year
<
0
)
return
0
;
if
(
month
>
12
)
return
0
;
if
(
month
==
1
||
month
==
3
||
month
==
5
||
month
==
7
||
month
==
8
||
month
==
10
||
month
==
12
)
{
if
(
day
>
31
)
return
0
;
}
if
(
month
==
4
||
month
==
6
||
month
==
9
||
month
==
11
)
{
if
(
day
>
30
)
return
0
;
}
if
(
month
==
2
)
{
if
(
year
%
4
||
(
year
%
100
==
0
&&
year
%
400
))
{
if
(
day
>
28
)
return
0
;
}
else
{
if
(
day
>
29
)
return
0
;
}
}
return
1
;
}
int
toBinary
(
int
input
)
{
if
(
input
>
1023
)
return
0
;
// Ran out of memory error
int
binLength
=
log
(
input
)
/
log
(
2
)
+
1
;
int
a
[
binLength
];
int
i
;
for
(
i
=
0
;
i
<
binLength
;
i
++
)
{
a
[
i
]
=
input
%
2
;
input
/=
2
;
}
unsigned
int
result
=
0
;
for
(
i
=
0
;
i
<
binLength
;
i
++
)
{
result
=
10
*
result
+
a
[
binLength
-
i
-
1
];
}
return
result
;
}
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