Commit 1a978213 by otsall

tbc

parent ed563653
Showing with 118 additions and 0 deletions
#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("\nBusiest 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;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment