**A**

#include <stdlib.h> /* rand() */

#include <time.h> /* time() */

#include <stdio.h> /* printf() */

#define N_OF_FRIENDS 3

#define MAX_MOTHER_CARE 10

#define MIN_MOTHER_CARE 1

int main() {

const unsigned SIZE = N_OF_FRIENDS;

int ArrayA[N_OF_FRIENDS] = { 0 }; /* initialize all the elements */

unsigned index = 0;

int Total = 0;

int Sum3 = 0;

srand((unsigned) time(0)); /* set new seed for a generator each time */

for (index = 0; index < SIZE; index++) {

ArrayA[index] /* generating numbers in a range */

= rand() % (MAX_MOTHER_CARE – MIN_MOTHER_CARE + 1) + MIN_MOTHER_CARE;

printf(“%d “, ArrayA[index]);

}

printf(“\n”);

/* We just need to check that total number of chocolates (Total) equals

* A[1] + (A[1] + 3) + (A[1] + 3 + 3) + … + (A[1] + 3 * (n – 1)), equals

* n * A[1] + 0 + 3 + 6 + … + 3 * (n – 1), where A[1] is a natural number.

* Or, in other words, the difference between total number of chocolates

* and (0 + 3 + 6 + … + 3 * (n – 1)) is divisible by n and positive.

* Or, in other words, Total – (0 + 3 + 6 + … + 3 * (n – 1)) % n = 0 and

* that difference is positive.

*/

for (index = 0; index < SIZE; index++) {

Total += ArrayA[index]; /* add and assign */

Sum3 += index * 3; /* add and assign */

}

if ((Total – Sum3) % 3 == 0 && (Total – Sum3) > 0) {

printf(“Yes, it is possible, %d, %d, A1=%d\n”,

Total, Sum3, (Total – Sum3) / 3);

} else {

printf(“No, it is impossible, %d, %d\n”,

Total, Sum3);

}

return 0;

}

**115**Views