Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 5 Structured Program.

Slides:



Advertisements
Similar presentations
More on Algorithms and Problem Solving
Advertisements

Code Visual to Flowchart Basem AL-yasouri Ayad R Meshalmeha Fadi Alalean Loay abu odah.
Introduction to Flowcharting
Introduction to Flowcharting
Introduction to Flowcharting
Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Published by Addison-Wesley.
Computer Programming Rattapoom Waranusast Department of Electrical and Computer Engineering Faculty of Engineering, Naresuan University.
C How to Program, 6/e Summary © by Pearson Education, Inc. All Rights Reserved.
 Control structures  Algorithm & flowchart  If statements  While statements.
Chapter 3 - Structured Program Development
© Copyright 1992–2004 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 1 Chapter 3 - Structured Program Development Outline.
 2000 Prentice Hall, Inc. All rights reserved. Chapter 3 - Structured Program Development Outline 3.1Introduction 3.2Algorithms 3.3Pseudocode 3.4Control.
Control Structures Control structures control the flow of program execution. 3 types of control structures: sequence, selection.
Chapter 4 Control Structure: Loop Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop.
Structured Program Development in C
(C)opyright 2003 Scott/Jones Publishers Introduction to Flowcharting A Supplement to Starting Out with C++, 4th Edition by Tony Gaddis Scott/Jones Publishers.
CSC103: Introduction to Computer and Programming
The University of Texas – Pan American
PROGRAMMING, ALGORITHMS AND FLOWCHARTS
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.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
1 Introduction to Flowcharting. 2 Writing a program Defining the problem –Write down what the program will do Planning –Write down the steps, draw a flowchart.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
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.
Pseudocode When designing an ALGORITHM to solve a problem, Pseudocode, can be used. –Artificial, informal language used to develop algorithms –Similar.
C Lecture Notes 1 Structured Program Development.
ITEC113 Algorithms and Programming Techniques
Internet & World Wide Web How to Program, 5/e © by Pearson Education, Inc. All Rights Reserved.
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.
 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.
Algorithm Design.
Lecture 4: C/C++ Control Structures Computer Programming Control Structures Lecture No. 4.
Structured Program Development Angela Chih-Wei Tang ( 唐 之 瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan 2010.
1 Lecture 3 Control Structures else/if and while.
`. Lecture Overview Structure Programming Basic Control of Structure Programming Selection Logical Operations Iteration Flowchart.
(C)opyright 2000 Scott/Jones Publishers Introduction to Flowcharting.
Think Possibility 1 Iterative Constructs ITERATION / LOOPS C provides three loop structures: the for-loop, the while-loop, and the do-while-loop. Each.
1 Introduction to Flowcharting Computer Science Principles ASFA.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Extended Prelude to Programming Concepts & Design, 3/e by Stewart Venit and.
CC213 Programming Applications Week #2 2 Control Structures Control structures –control the flow of execution in a program or function. Three basic control.
Sesi 0607EKT120/4 Computer Programming Week 5 – Repetition / Loops.
1 ICS103 Programming in C Lecture 7: Repetition Structures.
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.
ALGORITHMS AND FLOWCHARTS
Introduction to Flowcharting
REPETITION CONTROL STRUCTURE
Chapter 2.1 Control Structures (Selection)
Introduction to Flowcharting
CSC113: Computer Programming (Theory = 03, Lab = 01)
Introduction to Flowcharting
Ch 7: JavaScript Control Statements I.
Lecturer CS & IT Department UOS MBDIN
Programming Fundamentals
Control Structures Lecture 7.
Lecture 2: Logical Problems with Choices
How to develop a program?
MSIS 655 Advanced Business Applications Programming
Structured Program
Chapter 3 - Structured Program Development
3 Control Statements:.
Chapter 3 - Structured Program Development
Introduction to Flowcharting
Structural Program Development: If, If-Else
Presentation transcript:

Lecturer: Omid Jafarinezhad Sharif University of Technology Department of Computer Engineering 1 Fundamental of Programming (C) Lecture 5 Structured Program Development

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 2 How to develop a program? Requirements Problem Analysis Design Designing algorithm Pseudo codeFlow chart Implementation Implementing algorithm in c/c++ Validation Test Maintenance Software Development Life-Cycle Refinement

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 3

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 4 Requirements Discovery Problem Analysis – Problem Identification – Abstraction Inputs and outputs determination Defining their relation Write a program to compute an employee's weekly pay? How many hours did you work? How much do you get paid per hour? employee's weekly pay equal to multiplication of Hours by Pay Rate

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 5 Problem vs. Solution A problem is something that causes trouble The solution is how to solve or fixe the problem

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 6 Algorithm A procedure for solving a problem in terms of actions and the order in which these actions are to be executed in a computer program (program control) Action Order

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 7 Execution order Sequential execution, normally, statements in a program are executed one after the other in the order in which they’re written Various C statements enable you to specify that the next statement to be executed may be other than the next one in sequence. This is called transfer of control

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 8 Structured Programming goto statement that allows programmers to specify a transfer of control to one of many possible destinations in a program Research had demonstrated that programs could be written without any goto statements Programs produced with structured techniques were clearer, easier to debug and modify and more likely to be bug free in the first place. Research had demonstrated that all programs could be written in terms of only three control structures, namely the sequence structure, the selection structure and the repetition structure

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 9 Pseudo code An artificial and informal language that helps you develop algorithms – similar to everyday English – are not executed on computers – consists only of action statements pay-calculation program: 1.Read Hours and Pay Rate 2.weekly pay = Read Hours * Pay Rate

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 10 Flowchart A flowchart is a diagram that depicts the flow of an algorithm – pay-calculation program Each symbol represents a different type of operation START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 11 Terminals represented by rounded rectangles indicate a starting or ending point STARTEND START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Terminal Flow line

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 12 Input/Output Operations indicate an input or output operation Display message “How many hours did you work?” Read Hours START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Input/Output Operation

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 13 Processes indicates a process such as a mathematical computation or variable assignment START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Multiply Hours by Pay Rate. Store result in Gross Pay. Process

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 14 Execution START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Output Operation Variable Contents: Hours: ? Pay Rate: ? Gross Pay: ? How many hours did you work?

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 15 Execution START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ? How many hours did you work? 40 Input Operation (User types 40)

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 16 Execution START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Output Operation Variable Contents: Hours: 40 Pay Rate: ? Gross Pay: ? How much do you get paid per hour?

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 17 Execution START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: ? How many hours did you work? 20 Input Operation (User types 20)

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 18 Execution START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: 800 How many hours did you work? 20 Process (Gross Pay = Hours * Pay Rate)

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 19 Execution START Display message “How many hours did you work?” Read Hours Display message “How much do you get paid per hour?” Read Pay Rate Multiply Hours by Pay Rate. Store result in Gross Pay. Display Gross Pay END Variable Contents: Hours: 40 Pay Rate: 20 Gross Pay: 800 Your gross pay is 800 Output Operation

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 20 Connectors Sometimes a flowchart will not fit on one page – A connector (represented by a small circle) allows you to connect two flowchart segments A A START END

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 21 Modules A program module (such as a function in C) is represented by a special symbol The position of the module symbol indicates the point the module is executed A separate flowchart can be constructed for the module START END Read Input Call calc_pay function Display results module

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 22 Control Structures Sequence Decision selection statement – The if statement is called a single-selection statement because it selects or ignores a single action. – The if…else statement is called a double-selection statement because it selects between two different actions. – The switch statement is called a multiple-selection statement because it selects among many different actions Repetition – while – do…while – for

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 23 Sequence Structure a series of actions are performed in sequence – The pay-calculating example

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 24 Compound Statements A statement is a specification of an action to be taken by the computer as the program executes Compound Statements is a list of statements enclosed in braces, { }

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 25 Decision Structure One of two possible actions is taken, depending on a condition Selection structures are used to choose among alternative courses of action YESNO YESNO x < y? Process BProcess A

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 26 Decision Structure The flowchart segment below shows how a decision structure is expressed in C as an if/else statement YESNO x < y? Calculate a as x times 2. Calculate a as x plus y. if (x < y) a = x * 2; else a = x + y; FlowchartC programming language

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 27 Example Compound statement is way to group many statements together so they are treated as one if (grade >= 60) printf( "Passed.\n" ); // { printf( "Passed.\n" ); } else { printf( "Failed.\n" ); printf( "You must take this course again.\n" ); }

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 28 Decision Structure The flowchart segment below shows a decision structure with only one action to perform if (x < y) a = x * 2; FlowchartC programming language YESNO x < y? Calculate a as x times 2.

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 29 Combining Structures Display “x is within limits.” Display “x is outside the limits.” YESNO x > min? x < max? YES NO Display “x is outside the limits.” if (x > min) { if (x < max) printf("x is within the limits"); else printf("x is outside the limits"); } else printf("x is outside the limits");

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 30 Example int k = 1, m = 4; if (k < 2 || m == 3) { m = 2 + k, printf("%d", m); } else { k = 1, printf("%d", k); } int k = 1, m = 4; if (k < 2 || m == 3) { m = 2 + k; printf("%d", m); } else { k = 1; printf("%d", k); } Which is more readable?

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 31 Example if(x) if(y) printf("Yes"); else printf("No"); if(x) { if(y) printf("Yes"); else printf("No"); } if(x) { if(y) printf("Yes"); } else printf("No"); if (x < 0) sign = -1; else if (x == 0) sign = 0; else sign = 1; if (x < 0.25) count1++; else if (x >= 0.25 && x < 0.5) count2++; else if (x >= 0.5 && x < 0.75) count3++; else count4++;

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 32 Case Structure One of several possible actions is taken, depending on the contents of a variable

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 33 Case Structure indicates actions to perform depending on the value in years_employed CASE years_employed Other bonus = 100 bonus = 200 bonus = 400 bonus = 800 If years_employed = 1, bonus is set to 100 If years_employed = 2, bonus is set to 200 If years_employed = 3, bonus is set to 400 If years_employed is any other value, bonus is set to 800

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 34 switch A switch statement allows a single variable (integer or char) to be compared with several possible constants – A constant can not appear more than once, and there can only be one default expression

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 35 switch switch (variable) { case const: statements...; default: statements...; } switch (c = toupper(getch())) { case ‘R’: printf("Red"); break; case ‘G’: printf("Green"); break; default: printf("other"); }

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 36 Example switch(betty) { case 1: printf("betty = 1\n"); case 2: printf("betty=2\n"); break; case 3: printf("betty=3\n"); break; default: printf("Not sure\n"); } CASE betty? Other betty = 1 betty = 2 betty = 3 Not sure

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 37 Repetition Structure A loop tests a condition, and if the condition exists, it performs an action. Then it tests the condition again. If the condition still exists, the action is repeated. This continues until the condition no longer exists x < y? Process A YES

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 38 Repetition Structure The flowchart segment below shows a repetition structure expressed in C as a while loop while (x < y) x++; FlowchartC programming language x < y? Add 1 to x YES

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 39 While while (loop_repetition_condition) statement; OR //Compound statement while (loop_repetition_condition) { statement1; statement2; // … }

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 40 Controlling a Repetition Structure The action performed by a repetition structure must eventually cause the loop to terminate. Otherwise, an infinite loop is created In this flowchart segment, x is never changed. Once the loop starts, it will never end How can this flowchart be modified so it is no longer an infinite loop? x < y? Display x YES

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 41 Controlling a Repetition Structure Adding an action within the repetition that changes the value of x x < y? Display x Add 1 to x YES

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 42 A Pre-Test Repetition Structure This type of structure is known as a pre-test repetition structure. The condition is tested BEFORE any actions are performed – if the condition does not exist, the loop will never begin x < y? Display x Add 1 to x YES

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 43 Example int counter = 0; while (counter < 9) { printf("%d\n", counter ++); } int counter = 0; while (counter < 1000) ; while (1); int counter = 0; while (counter < 9) { printf("%d\n", counter); counter++; } int counter = 0; while (counter < 9) printf("%d\n", counter ++); int counter = 9; while (counter > 0) printf("%d\n", counter --);

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 44 A Post-Test Repetition Structure The condition is tested AFTER the actions are performed – A post-test repetition structure always performs its actions at least once Display x Add 1 to x YES x < y? do { printf(…); x++; } while (x < y); C programming language

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 45 do-while do statement; while (loop_repetition_condition) OR do //Compound statement { statement1; statement2; // … } while (loop_repetition_condition)

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 46 Example Input : 5 integer n1, n2, n3, n4, n5 Output: The summation of n1, n2,.., n5 Input example: Output example: 20 Can you identify the input and output? Draw a flowchart for the following problem: Read 5 integer and display the value of their summation.

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 47 Input n1 Input n2 Input n3 input n4 input n5 output sum sum ← n1+n2+n3+n4+n5 start 2 n1 Assume input example: n2 4 n3 5 n4 6 n5 20 sum end This flowchart does not use loop, hence we need to use 6 different variables

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 48 counter ← 1, sum ← 0 counter < 6 sum ← sum + n false true counter++ output sum input n 1 counter sum 0 1 < 6true 2 n < 6true < 6true < 6true < 6true < 6false Assume input example: This loop is counter-controlled This loop is counter-controlled The counter Increases by 1 The counter Increases by 1 Uses only 3 variables Uses only 3 variables

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 49 C Programming Language 49 Decreasing Counter-Controlled Loop counter ← 5, sum ← 0 counter > 0 sum←sum+ x false true counter-- output sum input x

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 50 For for (initial_value ; condition; update_counter) statement; OR // Compound statement for (initial_value ; condition; update_counter) { statement; statement; // … }

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 51 int x, sum, i; sum = 0; for (i = 0; i < 5; i++) { scanf(“%d”,&x); sum = sum + x; } printf(“%d”,sum); counter ← 1, sum ← 0 counter < 6 sum ← sum + n false true counter++ output sum input n

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 52 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num ??? _

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 53 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 1 _

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 54 num 1 _ Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”);

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 55 num 1 1_1_ Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”);

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 56 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 2 1_1_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 57 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 2 1_1_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 58 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 2 12_12_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 59 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 3 12_12_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 60 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 3 12_12_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 61 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 3 123_123_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 62 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 4 123_123_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 63 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 4 123_123_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 64 Example: for (num = 1; num <= 3; num++ ) printf(“%d\t”, num); printf(“have come to exit\n”); num 4 123have come to exit_

Structured Program Development – Lecture 5 Sharif University of Technology Department of Computer Engineering 65 Example * ** *** **** ***** ****** #include int main() { int iCounter = 0; int jCounter = 0; while (iCounter < 7) { jCounter = 0; while (jCounter < iCounter) { printf("*"); jCounter++; } printf("\n"); iCounter++; } getch(); return 0; }