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
08a41e85
authored
Oct 07, 2016
by
Gürcan Güleç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Committing lab3 homework
parent
dd943ffc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
84 additions
and
0 deletions
labs/lab3/array.c
labs/lab3/array.c
0 → 100644
View file @
08a41e85
/**
* File array.c
* Author: Gurcan Gulec
* Created: 06 October 2016
* Last edit: 07 October 2016
*
* Description: Homework about arrays for lab 3.
*
*/
#include <stdio.h>
#define ARRAYLENGHT 10
int
main
(
void
)
{
int
tempValue
;
int
i
,
j
;
int
a
;
float
sum
=
0
;
float
median
;
int
sumOfOdd
=
0
;
// creating the array
int
numbers
[
10
]
=
{
21
,
4
,
13
,
10
,
18
,
92
,
45
,
23
,
56
,
44
};
int
n
=
10
;
// sorting the numbers
for
(
i
=
0
;
i
<
n
-
1
;
i
++
)
{
for
(
j
=
0
;
j
<
n
-
i
-
1
;
j
++
)
{
if
(
numbers
[
j
]
>
numbers
[
j
+
1
])
{
tempValue
=
numbers
[
j
];
numbers
[
j
]
=
numbers
[
j
+
1
];
numbers
[
j
+
1
]
=
tempValue
;
}
}
}
// printing out the numbers in order
printf
(
"Sorted: "
);
for
(
i
=
0
;
i
<
n
;
i
++
)
{
printf
(
"%d "
,
numbers
[
i
]);
}
// printing out the smallest and the biggest number
printf
(
"
\n
Smallest: %d
\n
"
,
numbers
[
0
]);
printf
(
"Biggest: %d
\n
"
,
numbers
[
9
]);
// calculating the sum of the numbers and printing them out
for
(
a
=
0
;
a
<
n
;
a
++
)
{
sum
+=
numbers
[
a
];
}
printf
(
"Sum: %f
\n
"
,
sum
/
n
);
// finding the median
median
=
(
numbers
[
n
/
2
-
1
]
+
numbers
[
n
/
2
])
/
2
;
printf
(
"Median : %f
\n
"
,
median
);
// for "some other manipulation of numbers" i found the odd numbers and summed them up
for
(
int
j
=
0
;
j
<
n
;
j
++
)
{
if
(
numbers
[
j
]
%
2
)
{
sumOfOdd
+=
numbers
[
j
];
}
}
printf
(
"Sum of Odd Numbers: %d"
,
sumOfOdd
);
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