Lecturer CS & IT Department UOS MBDIN

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
 Control structures  Algorithm & flowchart  If statements  While statements.
 2002 Prentice Hall. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure.
Chapter 3 - Structured Program Development
Introduction to Computers and Programming Lecture 5 New York University.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
Introduction to Computers and Programming Lecture 5 Boolean type; if statement Professor: Evan Korth New York University.
Introduction to Computers and Programming Class 6 Introduction to C Professor Avi Rosenfeld.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Structured Program Development in C
Lecture 3 Structured Program Development in C
Examples from “c++ how to program” book. SELECTIONS WITH IF-ELSE Example: if ( grade >= 60) cout = 60) cout
The University of Texas – Pan American
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
 2003 Prentice Hall, Inc. All rights reserved.  2004 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1.
Spring 2005, Gülcihan Özdemir Dağ Lecture 3, Page 1 BIL104E: Introduction to Scientific and Engineering Computing, Spring Lecture 3 Outline 3.1 Introduction.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Structural Program Development: If, If-Else Outline.
Structured Program Development Outline 2.1Introduction 2.2Algorithms 2.3Pseudo code 2.4Control Structures 2.5The If Selection Structure 2.6The If/Else.
Lecture 2: Logical Problems with Choices. Problem Solving Before writing a program Have a thorough understanding of the problem Carefully plan an approach.
C Lecture Notes 1 Structured Program Development.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 The if Selection Structure 4.6 The if / else Selection Structure 4.7.
CMPSC 16 Problem Solving with Computers I Spring 2014 Instructor: Lucas Bang Lecture 5: Introduction to C: More Control Flow.
Dale Roberts 1 Program Control - Algorithms Department of Computer and Information Science, School of Science, IUPUI CSCI N305.
Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control Structures 3.5The If Selection Structure 3.6The.
 2003 Prentice Hall, Inc. All rights reserved. Chapter 8 - JavaScript: Control Statements I Outline 8.1 Introduction 8.2 Algorithms 8.3 Pseudocode 8.4.
 2008 Pearson Education, Inc. All rights reserved JavaScript: Control Statements I.
Lecture 2 Control Structure. Relational Operators -- From the previous lecture Relational Operator Meaning == is equal to < is less than > is greater.
 2003 Prentice Hall, Inc. All rights reserved. 1 Outline 4.1 Introduction 4.2 Algorithms 4.3 Pseudocode 4.4 Control Structures 4.5 if Single-Selection.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Unit 2 – Algorithms & Pseudocode. Algorithms Computer problems solved by executing series of action in order Procedure –The Actions to execute –The Order.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 Lecture 2 Control Structures: Part 1 Selection: else / if and switch.
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
Lecture 5: Layers of Control. Nested while Loops Problem Multiplying two numbers and outputting the result only if they are both less than 5. (i.e. Start.
ECE122 Feb 10, Unary Operator An operator that takes only a single operand Plus: + Minus: – Cast: (type). E.g. (double)
CHAPTER#3 STRUCTURED PROGRAM DEVELOPMENT IN C 1 A.AlOsaimi King Saud University College of Applied studies and Community Service Csc 1101.
Chapter 3 Structured Program Development in C C How to Program, 8/e, GE © 2016 Pearson Education, Ltd. All rights reserved.1.
1 Chapter 4 - Control Statements: Part 1 Outline 4.1 Introduction 4.4 Control Structures 4.5 if Selection Structure 4.6 if/else Selection Structure 4.7.
Chapter 7 JavaScript: Control Statements, Part 1
Algorithm: procedure in terms of
- Standard C Statements
Lecture 7: Repeating a Known Number of Times
JavaScript: Control Statements I
Chapter 2.1 Control Structures (Selection)
TMF1414 Introduction to Programming
Chapter 8 - JavaScript: Control Statements I
Ch 7: JavaScript Control Statements I.
Chapter 4 – Control Structures Part 1
Programming Fundamentals
JavaScript: Control Statements.
Programming Fundamentals Lecture #6 Program Control
Lecture 2: Logical Problems with Choices
How to develop a program?
Structured Program
1) C program development 2) Selection structure
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 3 – Control Structures
Chapter 3 - Structured Program Development
Introduction to Problem Solving and Control Statements
Chapter 4 - Control Structures: Part 1
Control Statements Paritosh Srivastava.
Dale Roberts, Lecturer IUPUI
Dale Roberts, Lecturer IUPUI
Structural Program Development: If, If-Else
Presentation transcript:

Lecturer CS & IT Department UOS MBDIN Programming Fundamentals Lecture #5 Principles of Structured and Modular Programming Junaid Hassan Lecturer CS & IT Department UOS MBDIN junaidte14@gmail.com

Algorithms Procedure for solving a problem by executing a series of actions and in a specific order is called an algorithm In any algorithm, the order in which the actions are executed is very important The order in which statements are executed in computer program is called program control

Pseudocode Pseudocode is an artificial and informal language that helps you develop algorithm Pseudocode Algorithms C Program Pseudocode is written in a language similar to everyday English It’s convinient and user friendly way to write code, although it’s not a computer programming language Pseudocode actually helps us to ‘think out’ or ‘plan’ before attempting to write it a programming language Pseudocode can be implemented in any programming language Pseudocode consists only of action statments (definitions like int i are not added in pseudocode)

Control Structures Statements in a program are executed one after the other in the order in which they’re written. This is called sequential execution Sometimes the next statment to be executed may be other than the next one in the sequence, this is called transfer of control e.g goto statement To write a program using transfer of control statements was difficult New research revealed that all programs can be written with only three control structures namely sequence structure, selection structure, and the repetition structure The sequence structure is the bulitin/default structure of C programming language i.e all statements by default execute one after the other in the order in which they are written

Control Structures In C three types of Selection Structures are available namely, single selection statement (if statement), double-selection statement (if- --else statement) and multiple-selection statement (switch statement) In C three types of Repetition Structures (or loops) are available namely, while loop, do- while loop and for loop

If Selection Statement Pseudodcode: If student’s grade is greater than or equal to 60 Print “Passed” C Code: if ( grade >= 60 ) { printf( "Passed\n" ); } /* end if */

If...else Selection Statement Pseudodcode: If student’s grade is greater than or equal to 60 Print “Passed” else Print “Failed” C Code: if ( grade >= 60 ) { printf( "Passed\n" ); } else { printf( "Failed\n" );

Nested Control Structures Nested if…else statements test for multiple cases by placing if…else statements inside if…else statements C Code: if ( grade != 60 ) { if(grade > 60){ printf(‘Your grade is greater than 60’); }else{ printf(‘Your grade is less than 60’); } else { printf( “your grade is equal to 60" );

While Repetition Statement A repetition statement allows you to specify that an action is to be repeated while some condition remains true. It’s also called as counter controlled repetition. In this repetition we exactly know how many times the statements will be repeated. Simple C program to print “Hello World” string 5 times i = 0; while ( i <= 4 ) { printf(‘Hello World! \n’); i = i+1; }

Used to assign values to the variable c = c + 3; or c += 3; Assignment Operators Used to assign values to the variable c = c + 3; or c += 3;

Increment and Decrement Operators Increment Operator & Decrement Operators Pre-Increment Operator, Pre-Decrement Operator Post-Increment Operator, Post-Decrement Operator