Sunday, March 5, 2023
HomeSoftware EngineeringInvite Extra Girls in C

# Invite Extra Girls in C

## The problem#

Process

King Arthur and his knights are having a New Years get together. Final yr Lancelot was jealous of Arthur, as a result of Arthur had a date and Lancelot didn’t, and so they began a duel.

To stop this from occurring once more, Arthur desires to ensure that there are not less than as many ladies as males at this yrâ€™s get together. He gave you a listing of integers of all of the get together goers.

Arthur wants you to return true if he wants to ask extra girls or false if he’s all set.

Enter/Output

• `[input]`Â integer arrayÂ `L`Â (`\$a`Â in PHP)

An array (assured non-associative in PHP) representing the genders of the attendees, the placeÂ `-1`Â representsÂ `girls`Â andÂ `1`Â representsÂ `males`.

`2 <= L.size <= 50`

• `[output]`Â a boolean worth`true`Â if Arthur want to ask extra girls,Â `false`Â in any other case.

Possibility 1:

``````#embody <stddef.h>

int invite_more_women(int *arr, size_t depend) {
int sum = 0;

for (int i = 0; i < depend; ++i) sum += arr[i];

return (sum>0)? 1 : 0;
}
``````

Possibility 2:

``````#embody <stddef.h>

int invite_more_women(int *arr, size_t depend) {
whereas (count--)
}
``````

Possibility 3:

``````#embody <stdbool.h>
#embody <stddef.h>

bool invite_more_women(const int attendee_genders[], size_t depend) {
ptrdiff_t sum = 0;
for (size_t i = 0; i < depend; i++)
sum += attendee_genders[i];
return sum > 0;
}
``````

## Check circumstances to validate our answer#

``````#embody <stdbool.h>
#embody <stddef.h>
#embody <criterion/criterion.h>

extern void do_test (size_t depend, const int array[count], bool anticipated);

#outline ARR_LEN(array) (sizeof(array) / sizeof *(array))

#outline sample_test(array, anticipated) do_test(ARR_LEN(array), array, anticipated)

Check(tests_suite, sample_tests)
{
sample_test(((int[]){1, -1, 1}), true);
sample_test(((int[]){-1, -1, -1}), false);
sample_test(((int[]){1, -1}), false);
sample_test(((int[]){1, 1, 1}), true);
do_test(0, NULL, false);
}
``````
RELATED ARTICLES