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

Homework-1 Student\'s Name: Faculty: Student Number: 1) Write a C progam that si

ID: 3701012 • Letter: H

Question

Homework-1 Student's Name: Faculty: Student Number: 1) Write a C progam that simulates the Champions League Group Stage Draws. Here are the steps your C code should do: Real Madrid, Barcelona, Leicester City, Bayern Manchen, Juventus, Benfica, Paris Saint-Germain, Moskva, Atltico Madrid, Borussia Dortmund, Arnsenal, Manchester City, Sevilla, Porto Leverkusen, Basel, Tottenham Hotspur, Dynamo Kyiv. Lyon, PSV Eindhoven, Sporting CP, Club Brugge, Borussia Mönchengladbach, Celtic, Monaco, Beyiktas, Legia Warszawa, Dinamo Zagreb, l FC Kobenhavn, Rostorv b. Draw random teams into 8 different groups. Reminder: One team can be chosen only ONCE! c. Sort each group according to their names d. Print each group on the screen. For example Group I 1. Arsenal 2. Barcelona 3. Celtic 4. Monaceo

Explanation / Answer

The c code would be

#include <stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
int size=4;
void sort(char *arr[])
{
int i,j;
char temp[100];
for(i=0;i<size;i++)
for(j=0;j<size-i-1;j++)
if(strcmp(arr[j],arr[j+1])>0)
{
strcpy(temp,arr[j]);
strcpy(arr[j],arr[j+1]);
strcpy(arr[j+1],temp);
}
}
//assuming there are 32 teams and 8 groups of size 4
int main()
{
srand(time(NULL));
char names[32]={};//enter the names of teams here as it is too long to type
char groups[8][4][100];/*making a 2d array of groups where each string has a max size of 100*/
int taken[32]={0};//an array depicting whether a tean has been selected or not
int i,j,k;
for(i=0;i<8;i++)
{
for(j=0;j<4;j++)
{
int r=rand()%32;
while(taken[r]!=0)
r=rand()%32;
strcpy(groups[i][j],names[r]);
taken[r]=1;
}
sort(groups[i]);
}
for(i=0;i<8;i++)
{
printf("Group %d ",i+1);
for(j=0;j<4;j++)
{
printf("%d. %s ",j+1,groups[i][j]);
}
printf(" ");
}
}

Do give a thumbs up and in case there are doubts leave a comment