Lecture4_handout

Lecture4_handout - 1 E140 Introduction to EE140...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 1 E140: Introduction to EE140: Introduction to Programming Concepts for Engineers Lecture 4 1 Program Selection Structured Programming Sequence structure election structure Selection structure if statement if-else statement switch statement Repetition structure while loop do-while loop for loop 2 All these 3 structures together, selection, sequence, and repetition, are referred as control structures. All C programs could be written in terms of these three types of control structures only and we call this structured programming. If statement if (expression) { if (grade > 90) { i tf("E ll t! ") Basic syntax: statements; } printf("Excellent!\n"); } Selectively executing statements if expression is true Relational Operators > if (c>b) if c is great than b >= if (c>=b) if c is great than or equal to b 3 < if (c<b) if c is less than b <= if (c<=b) if c is less than or equal to b == if (c==b) if c is equal to b != if (c!=b) if c is not equal to b Expression If the expression has a value 0, the expression is considered to be false; otherwise it is considered to be true if (1) is true all the time if (a) is true when a has a nonzero value if (b = 2) is always true and assigns 2 to b if (b = 0) is always false and assigns value 0 to b if (b == 0) is true if value of b is equal to 0 4 2 If-else statement if (a>=0){ Basic syntax: if (expression) { statements1; } else { statements2; } x = a; printf( “ Positive!\n ” ); } else { x = -a; printf( “ Negative!\n ” ); } Execute statements1 if expression is true; otherwise execute...
View Full Document

This note was uploaded on 09/04/2011 for the course EE 150 taught by Professor Lanxiang during the Spring '11 term at Montgomery College.

Page1 / 4

Lecture4_handout - 1 E140 Introduction to EE140...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online