-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproject3_teams.c
More file actions
83 lines (69 loc) · 1.99 KB
/
project3_teams.c
File metadata and controls
83 lines (69 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Anisha Hossain Megha (U43189731)
// This program assigns students to different teams based on their accumulated points.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
// function to ssign teams
void assign(int points[], int team_assignments[], int n)
{
for(int i = 0; i < n; i++)
{
int begginer_range = abs(points[i] - 25);
int honor_range = abs(points[i] - 70);
int exc_range = abs(points[i] - 125);
// beginner = 1, honor = 2, excellence = 3
if((begginer_range < honor_range) && (begginer_range < exc_range))
{
team_assignments[i] = 1;
}
else if((honor_range < begginer_range) && (honor_range < exc_range))
{
team_assignments[i] = 2;
}
else if((exc_range < begginer_range) && (exc_range < honor_range))
{
team_assignments[i] = 3;
}
}
}
// main function
int main(){
int n; // number of students
printf("Enter number of students: ");
scanf("%d", &n);
int points[n]; // points of each student
int team_assignments[n]; // student assignment
// storing number of points for each student
printf("Enter points for each student: ");
for(int i = 0; i < n; i++)
{
scanf("%d", &points[i]);
}
assign(points, team_assignments, n); // call to function
// printing student number based on assignment
printf("Beginner team: student");
for(int i = 0; i < n; i++)
{
if(team_assignments[i] == 1)
{
printf(" %d", i+1);
}
}
printf("\nHonor team: student");
for(int i = 0; i < n; i++)
{
if(team_assignments[i] == 2)
{
printf(" %d", i+1);
}
}
printf("\nExcellence team: student");
for(int i = 0; i < n; i++)
{
if(team_assignments[i] == 3)
{
printf(" %d", i+1);
}
}
return 0;
}