GoConqr hat ein neues Design! Sag uns, wie es dir gefällt.

Notizen

Revision

Laressa Hood Programming 159101 Undergrad Englisch 5 Seiten

Inhalt der Notizen (5)

Seite 1

The

Remainder Operation

The remainder

operation returns what is left over after groups have been formed. For example:

The result of 9 % 4 is 1

In other words, we have 9 things and we

remove groups of 4 (there are two groups) and then

there is one thing

left over (so the answer is 1). Other

examples:

The result of 3 % 3 is 0

The result of 9 % 5 is 4

The result of 2 % 3 is 2

Definitions:

Algorithm

A series of instructions

The order is important

You need a language

E.g. Baking

Computer Program

An algorithm

In a programming language (c)

In a form ready to run on a computer

Syntax

Rules of the language

Layout of your program

Grammar - is a collection of rules of the language

Semantics

Tells you the meaning of a piece of language

If and else statements:

if (value <= 15) {

Printf(“the value is less than or equal to 15”);

} else {

printf (“the value is greater then 15”);

}

Seite 2

Boolean data type

every variable has a data type

for example: int a, b;

Int = integar data type

Booleans are the result of a test; true or false

Better:

goes faster

uses less memory

Data types:

Boolean bool a, b; true, false

integer int e, f; 4 - 5, 65

real numbers float t, y; 3.14, 2.5, *8 - have to write as 8.0

Field width:

printf (“The value is %f”, value);

%4.2f

4 = total number of spaces

.2 number of after the dot.

%1.2f

ignores the 1, .2 is still carried out

Functions in stdlib.h:

exit(15); kills/stops the program

abs; calculates the absolute value of an integer (always positive)

distance = abs (b-a);

system; enables Dos (windows) commands from inside your program.

system(“cls”);

rand; produces a random number

Seite 3

Loops:

counter = 0;

while (counter < 5) {

printf("Hello");

counter++;

Checking Valid Input:

while (true) {

printf("Enter mark for test 1:\n");

scanf("%d", &mark1);

if ((mark1 >=0)&&(mark1<=50)) {

break;

} else {

printf("The mark must be from 0 to 50.\n");

Characters:

American Standard Code for Information Interchange (ASCII)

The ascii code for ‘A’ is 65, ‘a’ 97.

‘0’ (goes up to 9)can be written as a character, 48

‘ ‘ (space) 32

char k;

int main () {

k = ‘A’

printf (“The character is %c”, k);

There are 2 ways to input characters: (either or)

scanf (“%c” , &c);

k = getchar ();

Seite 4

scanf (“%c”, &k); - Don't forget &!!

scanf (“%d %d”, &a, &b);

getchar ();

Called a FLUSH

It doesn’t have a variable in front

Only used after scanf

is there to put up the enter from the screen so that Q can be read

Just get rid of enter

while (true) {

BLAH

if ((choice == ‘Q’)||(choice == ‘q’)) {

break;

} }

Seite 5

While (_Test_) - should i keep running

Initialise test variables

While (_Test_)

_

_

Change at least 1 test variable

}

While (true) - Is it true that i must stop?

Initialise test variables

While (true)

_

if (test)

break;

_

Change at least 1 test variable

}

Informationen

Beschreibung
Undergrad Programming 159101 Notiz am Revision, erstellt von Laressa Hood am 08/04/2016.
Erstellt von
Laressa Hood · Apr 2016
Aktualisiert
10 Apr 2016
Aufrufe
0
Bewertung

Feedback

Worum geht es?

Wie gefällt dir das neue Design?

Dein Eindruck