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
fc8b0469
authored
Dec 09, 2016
by
Gürcan Güleç
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
committing homework 2
parent
35eb18b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
99 additions
and
0 deletions
homework2/homework2.c
homework2/homework2.c
0 → 100644
View file @
fc8b0469
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
// to limit random created numbers between certain values
int
rndHigh
=
100
;
int
rndLow
=
1
;
int
clerk
;
// filling the matrix with random values
void
fillMatrix
(
int
arr
[
100
][
100
],
int
row
,
int
column
)
{
for
(
int
i
=
0
;
i
<
row
;
i
++
)
{
for
(
int
j
=
0
;
j
<
column
;
j
++
)
{
int
rnd
=
rndLow
+
(
rand
()
%
(
rndHigh
-
rndLow
));
arr
[
i
][
j
]
=
rnd
;
}
}
}
// reading from the matrix
void
readMatrix
(
int
arr
[
100
][
100
],
int
row
,
int
column
)
{
printf
(
"
\t
"
);
for
(
int
c
=
1
;
c
<
row
+
1
;
c
++
)
{
printf
(
"C%d "
,
c
);
}
printf
(
"
\n
"
);
for
(
int
i
=
0
;
i
<
row
;
i
++
)
{
printf
(
"ProDuck %d"
,
i
+
1
);
for
(
int
j
=
0
;
j
<
column
;
j
++
)
{
printf
(
"%5d "
,
arr
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
}
//finding the totals in each column
void
findTotals
(
int
arr
[
100
][
100
],
int
row
,
int
column
)
{
printf
(
" Total"
);
for
(
int
j
=
0
;
j
<
column
;
j
++
)
{
int
total
=
0
;
for
(
int
i
=
0
;
i
<
row
;
i
++
)
{
total
=
total
+
arr
[
i
][
j
];
}
printf
(
"%5d "
,
total
);
}
printf
(
"
\n
"
);
}
void
findClerk
(
int
arr
[
100
][
100
],
int
row
,
int
column
)
{
int
clerk
;
int
max
=
0
;
for
(
int
j
=
0
;
j
<
column
;
j
++
)
{
int
total
=
0
;
for
(
int
i
=
0
;
i
<
row
;
i
++
)
{
total
=
total
+
arr
[
i
][
j
];
}
if
(
max
<
total
)
{
max
=
total
;
clerk
=
j
+
1
;
}
}
printf
(
"
\n
"
);
printf
(
"Most ProDucktive Clerk: C%d"
,
clerk
);
printf
(
"
\n
"
);
}
void
displayMatrix
(
int
arr
[
100
][
100
],
int
row
,
int
column
)
{
readMatrix
(
arr
,
row
,
column
);
findTotals
(
arr
,
row
,
column
);
findClerk
(
arr
,
row
,
column
);
}
int
main
()
{
srand
(
time
(
NULL
)
);
int
matrix
[
100
][
100
];
int
r
=
5
;
int
c
=
5
;
fillMatrix
(
matrix
,
r
,
c
);
displayMatrix
(
matrix
,
r
,
c
);
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