Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
chazog
/
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
fb7223ef
authored
Dec 16, 2018
by
chazog
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Homework2
parent
75dbf9f8
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
138 additions
and
0 deletions
Homeworks/HW2_182451MVEB_Desmond_Azogu.c
Homeworks/HW2_182451MVEB_Desmond_Azogu.c
0 → 100644
View file @
fb7223ef
/**
* Author: Azogu Chibuzo Desmond
* Created: 13.11.2018
* Modified: 11.12.2018
* Description: This snippet of code helps make pairing the boys and girls and girls at a school dance conveniently.
*/
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
//declaring constants
#define MAXSIZE 15
#define FILEPROCESSING_H_
//function prototypes
void
readHeights
(
int
num
,
int
arr
[
MAXSIZE
]);
void
displayHeights
(
int
numBoys
,
int
numGirls
,
int
arrBoys
[
MAXSIZE
],
int
arrGirls
[
MAXSIZE
]);
void
sortHeights
(
int
num
,
int
arr
[
MAXSIZE
]);
void
displayPairs
(
int
numBoys
,
int
numGirls
,
int
arrBoys
[
MAXSIZE
],
int
arrGirls
[
MAXSIZE
]);
int
main
()
{
int
numBoys
;
int
numGirls
;
int
arrBoys
[
MAXSIZE
];
int
arrGirls
[
MAXSIZE
];
printf
(
"Enter number of boys: "
);
scanf
(
"%d"
,
&
numBoys
);
if
(
numBoys
>
15
)
{
/* if condition is true then print the following */
printf
(
"Number of Boys must be less than or equal to 15
\n
"
);
return
0
;
}
readHeights
(
numBoys
,
arrBoys
);
printf
(
"Enter number of girls: "
);
scanf
(
"%d"
,
&
numGirls
);
if
(
numGirls
>
15
)
{
/* if condition is true then print the following */
printf
(
"Number of Girls must be less than or equal to 15
\n
"
);
return
0
;
}
readHeights
(
numGirls
,
arrGirls
);
displayHeights
(
numBoys
,
numGirls
,
arrBoys
,
arrGirls
);
sortHeights
(
numBoys
,
arrBoys
);
sortHeights
(
numGirls
,
arrGirls
);
displayPairs
(
numBoys
,
numGirls
,
arrBoys
,
arrGirls
);
return
0
;
}
//Function to read the heights of boys and girls
void
readHeights
(
int
count
,
int
array
[
MAXSIZE
])
{
int
i
;
for
(
i
=
0
;
i
<
count
;
i
++
)
{
do
{
printf
(
"Enter height %d: "
,
i
+
1
);
scanf
(
"%d"
,
&
array
[
i
]);
}
while
(
array
[
i
]
<
0
);
}
}
//Function displays out the heights for the tallest boys and girls.
void
displayHeights
(
int
numBoys
,
int
numGirls
,
int
arrBoys
[
MAXSIZE
],
int
arrGirls
[
MAXSIZE
])
{
int
i
;
printf
(
"
\n
Height of the tallest Boys in the grouping: "
);
for
(
i
=
0
;
i
<
numBoys
;
i
++
)
{
printf
(
"|%d|"
,
arrBoys
[
i
]);
}
printf
(
"
\n
Height of the tallest Girls in the grouping: "
);
for
(
i
=
0
;
i
<
numGirls
;
i
++
)
{
printf
(
"|%d|"
,
arrGirls
[
i
]);
}
}
//function for sorting the heights
void
sortHeights
(
int
count
,
int
arr
[
MAXSIZE
])
{
int
i
,
j
,
temp
;
for
(
j
=
0
;
j
<
count
;
j
++
)
{
temp
=
arr
[
j
];
i
=
j
-
1
;
while
(
i
>=
0
&&
arr
[
i
]
>
temp
)
{
arr
[
i
+
1
]
=
arr
[
i
];
i
=
i
-
1
;
}
arr
[
i
+
1
]
=
temp
;
}
printf
(
"
\n
"
);
}
//function for pairing the tallest boy with the tallest girl
//function also prints out the unpaired tallest boy/girl for when the ratio of boys to girls are not equal
void
displayPairs
(
int
numBoys
,
int
numGirls
,
int
arrBoys
[
MAXSIZE
],
int
arrGirls
[
MAXSIZE
])
{
int
i
;
printf
(
"
\n
Pairs (boy, girl): "
);
if
(
numBoys
>
numGirls
)
{
for
(
i
=
0
;
i
<
numGirls
;
i
++
)
{
printf
(
"(%d, %d) "
,
arrBoys
[
i
],
arrGirls
[
i
]);
}
printf
(
"
\n
Boys without partner: "
);
for
(;
i
<
numBoys
;
i
++
)
{
printf
(
"|%d|"
,
arrBoys
[
i
]);
}
}
if
(
numBoys
<
numGirls
)
{
for
(
i
=
0
;
i
<
numBoys
;
i
++
)
{
printf
(
"(%d, %d) "
,
arrBoys
[
i
],
arrGirls
[
i
]);
}
printf
(
"
\n
Girls without partner:"
);
for
(;
i
<
numGirls
;
i
++
)
{
printf
(
"|%d|"
,
arrGirls
[
i
]);
}
}
printf
(
"
\n
"
);
}
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