• Wrong document? Swap it for free
  • Written by students who passed
  • Immediately available after payment
  • Read online or as PDF
Sell
Where do you study
Your language
Start selling Create your account
Document preview thumbnail
Preview 4 out of 84 pages
Exam (elaborations)

C language

Document preview thumbnail
Preview 4 out of 84 pages

Programming with C language and solving problems

Content preview

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

Document information

Study
Unknown
Uploaded on
March 22, 2023
Number of pages
84
Written in
2022/2023
Type
Exam (elaborations)
Contains
Questions & answers
£40.99

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Sold
1
Followers
0
Items
8
Last sold
3 months ago



Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their exams and reviewed by others who've used these revision notes.

Didn't get what you expected? Choose another document

No problem! You can straightaway pick a different document that better suits what you're after.

Pay as you like, start learning straight away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and smashed it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions