How to Welcome More Females in C

The difficulty

Job

King Arthur and his knights are having a New Years celebration. In 2015 Lancelot was envious of Arthur, due to the fact that Arthur had a date and Lancelot did not, and they began a battle.

To avoid this from occurring once again, Arthur wishes to make certain that there are at least as lots of ladies as guys at this year’s celebration. He offered you a list of integers of all the celebration goers.

Arthur requires you to return real if he requires to welcome more ladies or incorrect if he is all set.

Input/Output

  • [input] integer variety L ($ a in PHP)

A variety (ensured non-associative in PHP) representing the genders of the guests, where -1 represents ladies and 1 represents guys

2 < 0)? 1: 0;. }

  • [output] Choice 2: #include << stddef.h>>.

    int invite_more_women( int * arr, size_t count) {
    int balance = 0;.
    while (count--).
    balance += * arr++;.
    return balance > > 0;.
    }
    Choice 3: #include << stdbool.h>>.
    #include << stddef.h>>.

    bool invite_more_women( const int attendee_genders, size_t count) {
    ptrdiff_t amount = 0;.
    for (size_t i = 0; i < < count; i++). amount += attendee_genders

;.
return amount > > 0;.
}

#

 #include << stdbool.h>>.
#include << stddef.h>>.
#include << criterion/criterion. h>>.

extern space do_test (size_t count, const int variety[i], bool anticipated);.

#define ARR_LEN( variety) (sizeof( variety)/ sizeof *( variety)).

#define sample_test( variety, anticipated) do_test( ARR_LEN( variety), variety, anticipated).

Test( tests_suite, sample_tests).
{
sample_test((( int

) {1, -1, 1} ), real);.
sample_test((( int

) {-1, -1, -1} ), incorrect);.
sample_test((( int

) {1, -1} ), incorrect);.
sample_test((( int

) {1, 1, 1} ), real);.
do_test( 0, NULL, incorrect);.
}
[]

Like this post? Please share to your friends:
Leave a Reply

;-) :| :x :twisted: :smile: :shock: :sad: :roll: :razz: :oops: :o :mrgreen: :lol: :idea: :grin: :evil: :cry: :cool: :arrow: :???: :?: :!: