Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Lecture 3: Structured Programming and Control Structures in C - Prof. Lan Xiang, Study notes of Electrical and Electronics Engineering

The concepts of structured programming, control structures, if statement, if-else statement, switch statement, relational operators, and logic operators in c. It includes examples and sample code for grade calculation and quadratic equation root finding.

Typology: Study notes

Pre 2010

Uploaded on 03/11/2009

koofers-user-byz-1
koofers-user-byz-1 🇺🇸

5

(1)

10 documents

1 / 4

Toggle sidebar

Related documents


Partial preview of the text

Download Lecture 3: Structured Programming and Control Structures in C - Prof. Lan Xiang and more Study notes Electrical and Electronics Engineering in PDF only on Docsity! 1 1 EE114: Programming Concepts for Engineers Lecture 3 2 Overview n Structured programming n Selection structure n if statement n if-else statement n switch statement 3 Structured Programming n Sequence structure n Selection structure n if statement n if-else statement n switch statement n Repetition structure n while loop n do-while loop n for loop n 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. 4 If statement if (expression) statement; Expression Statement True False Exit Entry if (grade < 60) printf("Sorry, you failed this class!\n"); flowchart 2 5 if (expression) { statement_1; statement_2; …… statement_n; } If statement with compound statement if (a<5) { printf("a is less than 5"); printf("Sorry, data is not correct!\n"); } 6 If-else statement if (expression) statement0; else statement1; Expression Statement0 True False Exit Entry Statement1 if (a>=0) printf(“Positive!\n”); else printf(“Negative!\n”); 7 If-else with compound statement if (expression) { statement0; statement1; } else { statement3; statement4; } if (a>=0){ printf(“Positive!\n”); x=a; } else { printf(“Negative!\n”); x=-a; } 8 Relational Operators n > if (c>b) if c is great than b n >= if (c>=b) if c is great than or equal to b n < if (c<b) if c is less than b n <= if (c<=b) if c is less than or equal to b n == if (c==b) if c is equal to b n != if (c!=b) if c is not equal to b
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved