100 likes | 183 Views
Tuesday, 8 st of Aban 2 nd TA Session. Introduction to Programming Aideen nasirishargh. Let’s start real coding!. In last session, we did: Met with Memory and CPU Met with C++ and compared it, somehow, w/ C and Java Met with editors and compilers. Suggested DevCpp .
E N D
Tuesday, 8stof Aban 2ndTA Session Introduction to Programming Aideen nasirishargh
Let’s start real coding! • In last session, we did: • Met with Memory and CPU • Met with C++ and compared it, somehow, w/ C and Java • Met with editors and compilers. Suggested DevCpp. • Learnt how to run a “Hello World!” program and compile it! • In this session, we’re planned to: • What’s a program and how/who questions about its exec! • Meet with assignments and operators • Meet with if – The decision statement • While, as a repeating structure
How a program works • Algorithm! • What’s it? (water boiling sample!) • Computer is a logical machine and can hear only 0s and 1s, and nothing in the middle! • A computer Program • One ordered set of instructions to be executed one after another • They’ll be translated into assembly codes but we an consider them as is (i.e. complicated commands in one line!) • Each instruction: • Gives an info to machine (e.g. defining new variable) • Changes the status of the Machine (its memory, its running line) • Program Counter, a built-in variable for the program, • It’s auto-incremental
Sequential statements • Samples: • Calculation of a math formula! • Swap! • How to improve it?! • Solving a 2nd order equation
Is all running methods, top to bottom?! • How to skip one or more lines? • How to decide what to run, based on current state of machine (e.g. value of the variables) • Solution: if! • Let’s see an example… • Find equality • Find max, min • Find oddity If, this is the problem!
Doing something until getting to a wanted statement! That is “iteration”! Another core of programming. Syntax? While
Find number of bits a number needs • Number of digits • Sum of digits • Reverse number (1435 => 5341) • Prime Number • optimizations Practice
Thank you! Let’s go for some sleep :D Any question?