SOLENT UNIVERSITY
BSc (Hons) [Foundation]
Michele Accordino
Academic Year 2022-2023
Portfolio
Assignment 1
Submission Date:
3rd February 2023 Before 4pm (UK time)
Unit title: Problem Solving
Unit Code: QHO305
Unit Leather: Dhouha Kbaier
1
, SOLENT UNIVERSITY
Contents
Introduction..........................................................................................................................................3
Logical Operator...........................................................................................................................4
Relational Operator......................................................................................................................5
Escape sequence...........................................................................................................................5
Assessment 1........................................................................................................................................5
Introduction of Variables and Operators...........................................................................................5
Grade D........................................................................................................................................6
Grade C.........................................................................................................................................7
Grade B.........................................................................................................................................8
Grade A.........................................................................................................................................8
Assessment 2......................................................................................................................................10
Introduction of Conditional Statement...........................................................................................10
Grade D.......................................................................................................................................11
Grade C.......................................................................................................................................13
Grade B.......................................................................................................................................14
Grade A.......................................................................................................................................15
Assessment 3......................................................................................................................................17
Introduction of Loops.....................................................................................................................17
Grade D......................................................................................................................................18
Grade C.......................................................................................................................................20
Grade B.......................................................................................................................................22
Grade A.......................................................................................................................................25
Assessment 4......................................................................................................................................27
Grade D......................................................................................................................................27
Grade C.......................................................................................................................................30
Grade B.......................................................................................................................................34
Grade A.......................................................................................................................................36
Assessment 5......................................................................................................................................38
Introduction of Arrays....................................................................................................................38
Grade D......................................................................................................................................39
Grade C.......................................................................................................................................42
Grade B.......................................................................................................................................46
Grade A.......................................................................................................................................54
Differences between getchar(); and scanf();:..............................................................................54
Assessment 6......................................................................................................................................59
2
, SOLENT UNIVERSITY
Introduction to Sorting Algorithm..................................................................................................59
Grade D......................................................................................................................................60
Grade C.......................................................................................................................................61
Grade B.......................................................................................................................................62
Grade A.......................................................................................................................................63
Assessment 7......................................................................................................................................64
Introduction of Function.................................................................................................................64
Recursion....................................................................................................................................65
Grade D......................................................................................................................................66
Grade C.......................................................................................................................................69
Grade B.......................................................................................................................................72
Scope of Variable........................................................................................................................75
Class of Variable.........................................................................................................................75
Grade A.......................................................................................................................................76
Reflecting Report................................................................................................................................80
References..........................................................................................................................................82
Bibliography.......................................................................................................................................83
Appendices.........................................................................................................................................84
Introduction
What is Programming and C language?
3
, SOLENT UNIVERSITY
Programming is a serial of instruction that it is given to the computer. Those must be converted to one of the
languages used in the computer. This process is called compilation and it is using a software application
called compiler. C language is a binary language that the computer understands and one of the most used
programming languages. C was created by Dennis Ritchie at the Bell Laboratories in 1972. C is strongly
associated with UNIX, as it was developed to write the UNIX operating system. For this portfolio will be use
Replit.com but there are other program, like Visual Studio Code. The C program instruction start with the
main function, showed below.
#include <stdio.h>
int main(void)
{printf("Hello World\n");
return 0;}
The library stdio.h is the most used in C programming that contains input and output types, functions that the
program will use, this included almost the 75% of the C library, for example if the program needs
mathematic functions it needs to be included, in addition, #include<math.h>. The int main means that this is
our main function and (void) that doesn’t return to any other function. For include something that needs to be
show in our program we need to start with curly bracket and end with it. Printf followed with open and close
bracket and quotation marks open and close as well, it will print on our console what is inside, in this case
Hello World. \n is an escape sequence that we will talk about on the first assessment and on the end our
return 0; that tell the system that the program it might be terminated (in this assignment return 0; is not using
as not necessary to keep in the program). (Gookin, 2004)
In this Portfolio, it has been divided into functions, as showed below:
#include <stdio.h>
void gradeA();
void gradeB();
void gradeC();
void gradeD();
int main(void) {
int grade;
printf("Select the Grade.\n1-GradeD\n2-GradeC\n3-GradeB\n4-GradeA\
n");
scanf("%d", &grade);
if (grade == 1) {
gradeD();
} else if (grade == 2) {
gradeC();
} else if (grade == 3) {
gradeB();
} else if (grade == 4) {
gradeA();
} else {
printf("Wrong digit! Try again between 1 and 4.");}
}
N.B.: Functions will be explained in Assessment 7 of this Portfolio.
Logical Operator
Logical Operator is using for decision-making, there are three main logical operators showed below.
4
BSc (Hons) [Foundation]
Michele Accordino
Academic Year 2022-2023
Portfolio
Assignment 1
Submission Date:
3rd February 2023 Before 4pm (UK time)
Unit title: Problem Solving
Unit Code: QHO305
Unit Leather: Dhouha Kbaier
1
, SOLENT UNIVERSITY
Contents
Introduction..........................................................................................................................................3
Logical Operator...........................................................................................................................4
Relational Operator......................................................................................................................5
Escape sequence...........................................................................................................................5
Assessment 1........................................................................................................................................5
Introduction of Variables and Operators...........................................................................................5
Grade D........................................................................................................................................6
Grade C.........................................................................................................................................7
Grade B.........................................................................................................................................8
Grade A.........................................................................................................................................8
Assessment 2......................................................................................................................................10
Introduction of Conditional Statement...........................................................................................10
Grade D.......................................................................................................................................11
Grade C.......................................................................................................................................13
Grade B.......................................................................................................................................14
Grade A.......................................................................................................................................15
Assessment 3......................................................................................................................................17
Introduction of Loops.....................................................................................................................17
Grade D......................................................................................................................................18
Grade C.......................................................................................................................................20
Grade B.......................................................................................................................................22
Grade A.......................................................................................................................................25
Assessment 4......................................................................................................................................27
Grade D......................................................................................................................................27
Grade C.......................................................................................................................................30
Grade B.......................................................................................................................................34
Grade A.......................................................................................................................................36
Assessment 5......................................................................................................................................38
Introduction of Arrays....................................................................................................................38
Grade D......................................................................................................................................39
Grade C.......................................................................................................................................42
Grade B.......................................................................................................................................46
Grade A.......................................................................................................................................54
Differences between getchar(); and scanf();:..............................................................................54
Assessment 6......................................................................................................................................59
2
, SOLENT UNIVERSITY
Introduction to Sorting Algorithm..................................................................................................59
Grade D......................................................................................................................................60
Grade C.......................................................................................................................................61
Grade B.......................................................................................................................................62
Grade A.......................................................................................................................................63
Assessment 7......................................................................................................................................64
Introduction of Function.................................................................................................................64
Recursion....................................................................................................................................65
Grade D......................................................................................................................................66
Grade C.......................................................................................................................................69
Grade B.......................................................................................................................................72
Scope of Variable........................................................................................................................75
Class of Variable.........................................................................................................................75
Grade A.......................................................................................................................................76
Reflecting Report................................................................................................................................80
References..........................................................................................................................................82
Bibliography.......................................................................................................................................83
Appendices.........................................................................................................................................84
Introduction
What is Programming and C language?
3
, SOLENT UNIVERSITY
Programming is a serial of instruction that it is given to the computer. Those must be converted to one of the
languages used in the computer. This process is called compilation and it is using a software application
called compiler. C language is a binary language that the computer understands and one of the most used
programming languages. C was created by Dennis Ritchie at the Bell Laboratories in 1972. C is strongly
associated with UNIX, as it was developed to write the UNIX operating system. For this portfolio will be use
Replit.com but there are other program, like Visual Studio Code. The C program instruction start with the
main function, showed below.
#include <stdio.h>
int main(void)
{printf("Hello World\n");
return 0;}
The library stdio.h is the most used in C programming that contains input and output types, functions that the
program will use, this included almost the 75% of the C library, for example if the program needs
mathematic functions it needs to be included, in addition, #include<math.h>. The int main means that this is
our main function and (void) that doesn’t return to any other function. For include something that needs to be
show in our program we need to start with curly bracket and end with it. Printf followed with open and close
bracket and quotation marks open and close as well, it will print on our console what is inside, in this case
Hello World. \n is an escape sequence that we will talk about on the first assessment and on the end our
return 0; that tell the system that the program it might be terminated (in this assignment return 0; is not using
as not necessary to keep in the program). (Gookin, 2004)
In this Portfolio, it has been divided into functions, as showed below:
#include <stdio.h>
void gradeA();
void gradeB();
void gradeC();
void gradeD();
int main(void) {
int grade;
printf("Select the Grade.\n1-GradeD\n2-GradeC\n3-GradeB\n4-GradeA\
n");
scanf("%d", &grade);
if (grade == 1) {
gradeD();
} else if (grade == 2) {
gradeC();
} else if (grade == 3) {
gradeB();
} else if (grade == 4) {
gradeA();
} else {
printf("Wrong digit! Try again between 1 and 4.");}
}
N.B.: Functions will be explained in Assessment 7 of this Portfolio.
Logical Operator
Logical Operator is using for decision-making, there are three main logical operators showed below.
4