Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Student Number: Department: Write a C program that simulates the Champions Leagu

ID: 3702719 • Letter: S

Question

Student Number: Department: Write a C program that simulates the Champions League Group Stage Draws. Here are the steps your C code should do: a. Assign these teams to a one-dimensional array: Real Madrid, Barcelona, Leicester City, Bayern Manchen, Juventus, Benfica, Paris Saint-Germain, CSKA Moskva. Atletico Madrid, Borussia Dortmund, Arsenal, Manchester City, Sevilla, Porto, Napoli, Bayer Leverkusen, Basel. Tottenham Hotspur, Dynamo Kyiv. Lyon, PSV Eindhoven, Sporting CP, Club Bruge. Borussia Mönchengladbach, Celtic, Monaco, Be?iktas: Legia Warszawa, Dinamo Zagreb FC Kobenhavn, Rostov , Ludogorets Razgrad, b. Draw random teams into 8 different groups. Reminder: One team can be chosen only ONCE!!! Sort each group according to their names. Print each group on the sereen. For example: d. Group l I.Arsenal 2. Barcelona Celtic 4. Monaco 2) After finishing your program, a. Copy your codes to this word tile e pdf

Explanation / Answer

#include <stdio.h>

int main() {

int n = 32;

char strings[32][256] = { "Real Madrid", "Barcelona", "Leicester City",

"Bayern Monchen", "Juventus", "Benfica", "Paris Saint-Germain",

"CSKA Moskova", "Atletico Madrid", "Borussia Dortmund", "Arsenal",

"Manchester City", "Sevilla", "Porto", "Napoli", "Bayer Leverkusen",

"Basel", "Tottenham Hotspur", "Dynamo Kyiv", "Lyon",

"PSV Eindhoven", "Sporting CP", "Club Brugge",

"Borussia Mönchengladbach", "Celtic", "Monaco", "Be?ikta?",

"Legia Warszawa", "Dinamo Zagreb", "Ludogorets Razgrad",

"F.C. Kobenhavn", "Rostov" };

char final[32][256];

printf("The Teams are ");

for (int i = 0; i < n; i++) {

printf("%s ", strings[i]);

}

printf("Dividing Teams into 8 groups...... ");

//from the group of teams

int choice[n];

for (int i = 0; i < n; i++)

choice[i] = -1;

//initializing the srand function

srand (time(NULL));

int counter = 0, random;

int inArray;

while (counter < n) {

//generating random number

random = rand() % n;

inArray = 0;

for (int i = 0; i < n; i++) {

if (choice[i] == random)

inArray = 1;

}

if (!inArray) {

//copying the random string into final 2D array

strcpy(final[counter], strings[random]);

choice[counter] = random;

counter++;

}

}

//printing the resulted teams on the screen

printf(" The final Teams are ");

for (int i = 0; i < n; i++) {

if (i == 0) {

printf(" Group %d ", i + 1);

printf("--------- ");

} else if (i == 7) {

printf(" Group %d ", 2);

printf("--------- ");

} else if (i == 15) {

printf(" Group %d ", 3);

printf("--------- ");

} else if (i == 23) {

printf(" Group %d ", 4);

printf("--------- ");

}

printf("%s ", final[i]);

}

}