Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
otsall
/
iax0583
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
1a978213
authored
Nov 11, 2018
by
otsall
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
tbc
parent
ed563653
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
118 additions
and
0 deletions
Homework2/homework2.c
Homework2/homework2.c
0 → 100644
View file @
1a978213
#include <stdio.h>
#define MAXSIZE 15
void
fillMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
);
void
printMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
);
void
totalFlights
(
int
flights
[][
MAXSIZE
],
int
sum
[],
int
dest
,
int
carrier
);
void
busiestCarrier
(
int
sum
[],
int
carrier
);
int
main
()
{
int
dest
,
carrier
;
puts
(
"please input the number of destinations"
);
scanf
(
"%d"
,
&
dest
);
while
(
dest
>
MAXSIZE
||
dest
<
1
){
printf
(
"the number of destinations has to be between 1 and %d, try again
\n
"
,
MAXSIZE
);
scanf
(
"%d"
,
&
dest
);
}
puts
(
"please input the number of carriers"
);
scanf
(
"%d"
,
&
carrier
);
while
(
carrier
>
MAXSIZE
||
carrier
<
1
){
printf
(
"the number of carriers has to be between 1 and %d, try again
\n
"
,
MAXSIZE
);
scanf
(
"%d"
,
&
carrier
);
}
int
flightPlan
[
dest
][
carrier
],
sum
[
carrier
];
fillMatrix
(
flightPlan
,
dest
,
carrier
);
printMatrix
(
flightPlan
,
dest
,
carrier
);
totalFlights
(
flightPlan
,
sum
,
dest
,
carrier
);
busiestCarrier
(
sum
,
carrier
);
return
0
;
}
void
fillMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
){
int
i
,
j
;
puts
(
"please input the flight plan for"
);
for
(
i
=
0
;
i
<
dest
;
i
++
){
printf
(
"destination %d
\n
"
,
i
+
1
);
for
(
j
=
0
;
j
<
carrier
;
j
++
){
scanf
(
"%d"
,
&
flights
[
i
][
j
]);
while
(
flights
[
i
][
j
]
<
0
){
puts
(
"you cant fly negatively, try again"
);
scanf
(
"%d"
,
&
flights
[
i
][
j
]);
}
}
}
return
;
}
void
printMatrix
(
int
flights
[][
MAXSIZE
],
int
dest
,
int
carrier
){
int
i
,
j
;
puts
(
"Flights : "
);
printf
(
" "
);
for
(
i
=
0
;
i
<
carrier
;
i
++
){
printf
(
"C%d, "
,
i
+
1
);
}
printf
(
"
\n
"
);
for
(
i
=
0
;
i
<
dest
;
i
++
){
printf
(
"DESTINATION%d "
,
i
+
1
);
for
(
j
=
0
;
j
<
carrier
;
j
++
){
printf
(
"%d "
,
flights
[
i
][
j
]);
}
printf
(
"
\n
"
);
}
return
;
}
void
totalFlights
(
int
flights
[][
MAXSIZE
],
int
sum
[],
int
dest
,
int
carrier
){
int
i
,
j
,
add
=
0
;
for
(
i
=
0
;
i
<
carrier
;
i
++
){
for
(
j
=
0
;
j
<
dest
;
j
++
){
add
+=
flights
[
j
][
i
];
}
sum
[
i
]
=
add
;
add
=
0
;
}
printf
(
" TOTAL "
);
for
(
i
=
0
;
i
<
carrier
;
i
++
){
printf
(
"%d "
,
sum
[
i
]);
}
return
;
}
void
busiestCarrier
(
int
sum
[],
int
carrier
){
int
i
,
j
=
0
,
k
;
for
(
i
=
0
;
i
<
carrier
;
i
++
){
if
(
j
<
sum
[
i
]){
j
=
sum
[
i
];
k
=
i
;
}
}
printf
(
"
\n
Busiest carrier(s): C%d"
,
k
+
1
);
for
(
i
=
0
;
i
<
carrier
;
i
++
){
if
(
j
==
sum
[
i
]){
if
(
i
==
k
){
continue
;
}
else
{
printf
(
", C%d"
,
i
+
1
);
}
}
}
return
;
}
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