Docsity

Introduction to Programming Languages, Schemes and Mind Maps of Mathematics

Partial preview of the text

Download Introduction to Programming Languages and more Schemes and Mind Maps Mathematics in PDF only on Docsity!

Assoc. Prof. Dr. Tansu FİLİK

Bil 200 Week - 2

Previously on Bil 200

 Programming Languages (Machine Code, Assembly code, high-level languages)  Compiler (translator)  Software development (components of algorithm)  Top-Down software development  Elements of C-programming language

Variables and Values

int and float

 Integers (int)

 Floating point (real) numbers

- 1e

Bil200 – Computer Programming

Variables and Values

Characters (char)

 characters 'a' 'z' 'A' 'Z' '?' '@' '0' '9‘  Special characters are obtained using a \ sign before the indicator.  \n : skip to new line  \t : tab – skip 8 character spaces  ' : print out '  \ : print out backslash
etc..

Math Expressions

 They combine or change values of variables.

 Operators: + - * / %

 Functions: exp(), cos(), log()

 They return a value with a specific type.

Exercises

 Exercise 1

Calculate the area of a triangle whose base

length (b) and height (h) are given.

Read b and h values

Area ½ * b * h

Print Area

Exercises

 Exercise 3 For an average speed H, calculate the required amount of time for a travel between two locations that have distance U. Read H and U time U/H Print time

Exercises

 Exercise 4 Write a list of commands to read midterm, homework, and final grades of a student and calculate the total grade. The weight of final is twice of the midterm. Midterm and home work have the same weight. Read midterm, homework, and final total midterm + homework + 2*final average total / 4 Print average

Increment / decrement operators

 ++ is an increment operator.

i++;  means i = i + 1;

 -- is a decrement operator

j--;  means j = j - 1;  According to using “before” or “after” the variable, the operators may work slightly differently. i++; or ++i; do the same thing, but inherently, they work in a different manner with a different set of machine code instructions.

Increment / decrement operators

++k increment k by 1, and return the result to the expression that “uses” ++k.  k++ use the value of k in the expression that “uses” k++, and then increment the value of k by 1.  --k decrement k by 1, and return the result to the expression that “uses” --k.  k-- use the value of k in the expression that “uses” k--, and then decrement the value of k by 1.

Examples

 d - = 4 (d = d - 4)  e *= 5 (e = e * 5)  f /= 3 (f = f / 3)  g %= 9 (g = g % 9)  If the value of i is 5;  printf( "%d", ++i ); => Prints 6 on screen  printf( "%d", i++ ); => Prints 5 on screen In both cases, the value of i after execution is 6.

Exercise

*Determine the values of the variables after the following lines. Do it by hand first, then try at the computer. int i, j, k; i = 2; j = 3 + i++; k = 3 + ++i; i = ++k + j--; i /= k-- + ++j;

Type casting

Supported integer types

 C language has several integer types.  char 8 bit  short 16 bit  unsigned short 16 bit  int 32 bit  unsigned int 32 bit  long int 32 bit  unsigned long 32 bit

Type casting

Supported floating types

 C language has several floating point types.  float 32 bit  double 64 bit  long double 64 bit