Assignment 2
Assignment 2
Exercise 1 – Pattern
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n;
scanf("%d",&n);
char a=65;
int reminder=n%27;
int r=n/27;
a+=(reminder+r);
else
printf("%c", a);
}
printf("\n");
a-=1;
return 0;
}
int main() {
int nrStudents, questions;
char correct_answers[40];
char student_answers[100][40];
// Ask the user to enter the students' answers //
printf("Enter the students answers: ");
for (int i = 0; i < nrStudents; i++) {
for (int j = 0; j < questions; j++) {
scanf(" %c", &student_answers[i][j]);
}
}
return 0;
}
i=2
Memory Correct Student 3 Index C.A == S.A Cnt=0 Points+=cnt(100/5) Class
location answers(C.A) answers(S.A) (i) If C.A==S.A total
Cnt++
101xx A 201yy A 0 C.A(0) == S.A(0) 1 Points = 20 260
102xx B 202yy C 1 C.A(1) == S.A(1) 1 Points = 20
103xx C 203yy C 2 C.A(2) == S.A(2) 1 Points = 40
104xx D 204yy D 3 C.A(3) == S.A(3) 2 Points = 60
105xx E 205yy E 4 C.A(4) == S.A(4) 3 Points = 80
class_average=class_Total/nrOfStudents = 260/3 = 86.67
if (cnt != 0){
return;
}
int main() {
int nrOfnumbers;
// Ask and scan how many numbers the user is going to store in the list //
printf("Enter the number of numbers you want to store: ");
scanf("%d", &nrOfnumbers);
int list[nrOfnumbers];
int numbers ;
scanf("%d", &list[i]);
}
// Ask the user which is the number they are searching for //
printf("Enter the number you are searching for: ");
scanf("%d", &numbers);
// Use the function to compare the numbers stored in array //
arrCmp(list,nrOfnumbers,numbers);
return 0;
}
// convert results //
for (int i = 0; i < 150; ++i) {
if (points[i] == 0)
sum += 0;
else if (points[i] == 1)
sum += 1;
else if (points[i] == 2)
sum += 3;
}
return sum;
}
int main() {
int nrOfTeams, pointsToStay;
return 0;
}
After declairing variables and team names arrays, we scan the number of teams
and the number of points required to stay in league A.
Then call the function to read team names and calculate points
Function: readTeamNames
Iterating over each team:
Team 1:
Read team name: "Team1"
Call readTeamPoints function to read results: 0 1 2 ;
Calculate points for Team1: (0 + 1 + 3) = 4
Team 2:
Read team name: "Team2"
Call readTeamPoints function to read results: 2 1 0 ;
Calculate points for Team2: (3 + 1 + 0) = 4
Team 3:
Read team name: "Team3"
Call readTeamPoints function to read results: 1 2 2 ;
Calculate points for Team3: (1 + 3 + 3) = 7