Concept of algorithms Understand and use three tools to represent algorithms: Flowchart Pseudocode Programs

Size: px
Start display at page:

Download "Concept of algorithms Understand and use three tools to represent algorithms: Flowchart Pseudocode Programs"

Transcription

1 Morteza Noferesti

2 Concept of algorithms Understand and use three tools to represent algorithms: Flowchart Pseudocode Programs

3 We want to solve a real problem by computers Take average, Sort, Painting, Web, Multimedia,.. We need a solution that Specifies how the real (complex) problem should be solved stepby-step using the basic operations The solution is the Algorithm of the problem Characteristics Specific Unambiguous Language independent

4 Algorithms are the problem solving steps/strategy in our mind!!! How can we document it (don t forget it)? How can explain/teach it to others peoples? How can explain it to computers? We need some methods to describe algorithms! Flow chart Pseudo-codes Codes/Programs

5 A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem this sequence of steps is called an algorithm Implementation phase implement the program in some programming language

6 First produce a general algorithm (one can use pseudo code) Refine the algorithm successively to get step by step detailed algorithm that is very close to a computer language.

7 Pseudo code is an artificial and informal language that helps programmers develop algorithms. Pseudo code is very similar to everyday English. Employs 'programming-like' statements to depict the algorithm No standard format (language independent)

8 Write an algorithm to determine a student s final grade and indicate whether it is passing or failing. The final grade is calculated as the average of four marks.

9 Input a set of 4 marks Calculate their average by summing and dividing by 4 if average is below 50 Print FAIL else Print PASS

10 Step 1: Input M1,M2,M3,M4 Step 2: GRADE M1+M2+M3+M4)/4 Step 3: if (GRADE < 50) then Print FAIL else Print PASS endif

11 A graphical representation of the sequence of operations in an information system or program. A Flowchart shows logic of an algorithm emphasizes individual steps and their interconnections e.g. control flow from one action to the next

12 Name Symbol Use in Flowchart Oval Denotes the beginning or end of the program Parallelogram Denotes an input operation Rectangle Denotes a process to be carried out e.g. addition, subtraction, division etc. Diamond Denotes a decision (or branch) to be made. The program should continue along one of two routes. (e.g. IF/THEN/ELSE) Hybrid Denotes an output operation Flow line Denotes the direction of logic flow in the program

13 START Input M1,M2,M3,M4 GRADE (M1+M2+M3+M4)/4 Step 1: Input M1,M2,M3,M4 Step 2: GRADE (M1+M2+M3+M4)/4 Step 3: if (GRADE <50) then Print FAIL else Print PASS endif N IS GRADE<50 Y PRINT PASS PRINT FAIL STOP

14 Write an algorithm and draw a flowchart to convert the length in feet to centimeter. Pseudo code: Input the length in feet (Lft) Calculate the length in cm (Lcm) by multiplying LFT with 30 Print length in cm (LCM)

15 Flowchart Algorithm Step 1: Input Lft Step 2: Lcm Lft x 30 Step 3: Print Lcm START Input Lft Lcm Lft x 30 Print Lcm STOP

16 START Display message How many hours did you work? A flowchart for the pay-calculating program 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

17 Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area. Pseudo code Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

18 START Algorithm Step 1: Step 2: Step 3: Input W,L A L * W Print A Input W, L A L * W Print A STOP

19 Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation 2 ax bx c 2 Hint: d = sqrt ( b 4ac ), and the roots are: x1 = ( b + d)/2a and x2 = ( b d)/2a 0

20 Pseudo code: Input the coefficients (a, b, c) of the quadratic equation Calculate d Calculate x1 Calculate x2 Print x1 and x2

21 START Algorithm: Step 1: Input a, b, c Step 2: d sqrt ( ) Step 3: x1 ( b + d) / (2 x a) Step 4: x2 ( b d) / (2 x a) Step 5: Print x1, x2 b b 4 a c Input a, b, c d sqrt(b x b 4 x a x c) x 1 ( b + d) / (2 x a) X 2 ( b d) / (2 x a) Print x 1,x 2 STOP

22 The structure is as follows If condition then true alternative//s1 else false alternative//s2 endif Y condition N S1 S2

23 The expression A>B is a logical expression if A>B is true (if A is greater than B) we take the action on left print the value of A if A>B is false (if A is not greater than B) we take the action on right print the value of B Y is A>B N Print A Print B

24 Conditions by comparisons; e.g., If a is greater then b If c equals to d Comparing numbers: Relational Operators

25 Relations produce a boolean value int a, b; bool bl; // #include <stdbool.h> bl = a == b; bl = a <= b; C Boolean operators and && or not!

26 p q p && q p q!p False False False False True False True False True True True False False True False True True True True False

27 Examples bool a = true, b=false, c; c =!a; //c=false c = a && b; //c=false c = a b; //c=true c =!a b; //c=false

28 Write an algorithm that reads two values, determines the largest value and prints the largest value with an identifying message. ALGORITHM Step 1: Step 2: Step 3: Input VALUE1, VALUE2 if (VALUE1 > VALUE2) then MAX VALUE1 else MAX VALUE2 endif Print The largest value is, MAX

29 START Input VALUE1,VALUE2 Y is VALUE1>VALUE2 N MAX VALUE1 MAX VALUE2 Print The largest value is, MAX STOP

30 NO x > min? YES Display x is outside the limits. NO x < max? YES Display x is outside the limits. Display x is within limits.

31 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");

32 Write and algorithm to a) read an employee name (NAME), overtime hours worked (OVERTIME), hours absent (ABSENT) and b) determine the bonus payment (PAYMENT). Bonus Schedule OVERTIME (2/3)*ABSENT >40 hours >30 but 40 hours >20 but 30 hours >10 but 20 hours 10 hours Bonus Paid $50 $40 $30 $20 $10

33 Step 1: Input NAME,OVERTIME,ABSENT Step 2: if (OVERTIME (2/3)*ABSENT > 40) then PAYMENT 50 else if (OVERTIME (2/3)*ABSENT > 30) then PAYMENT 40 else if (OVERTIME (2/3)*ABSENT > 20) then PAYMENT 30 else if (OVERTIME (2/3)*ABSENT > 10) then PAYMENT 20 else PAYMENT 10 endif Step 3: Print Bonus for, NAME is $, PAYMENT

34 Algorithm: calculate n 2 Input: n Output: sum sum 0 i 1 Repeat the following three steps while i n: sq i * i sum sum + sq i i + 1

35

36

37 The flowchart reads three numbers and prints the value of the largest number.

38 Step 1: Input N1, N2, N3 Step 2: if (N1>N2) then if (N1>N3) then MAX N1 [N1>N2, N1>N3] else MAX N3 [N3>N1>N2] endif else if (N2>N3) then MAX N2 [N2>N1, N2>N3] else MAX N3 [N3>N2>N1] endif endif Step 3: Print The largest number is, MAX

39 #include <stdio.h> int main(void){ int number_to_test, remainder; printf("enter your number to be tested: "); scanf("%d", &number_to_test); remainder = number_to_test % 2; if(remainder == 0) else printf ("The number is even.\n ) } printf ("The number is odd.\n ) return 0;

40 Assign value according to conditions A ternary operator int i, j, k; bool b;... i = b? j : k; /*if(b) * i=j * else * i=k; */

41 y = abs(x) y = (x > 0)? x : -x; signum = (x < 0)? -1 : (x > 0? 1 : 0)

42 int d = numg / 25; charg = (d == 0)? D : ((d == 1)? C : (d == 2)? B : A );

43 Danger of assignment (=) and equality (==) int a = 10; int b = 20; if(a=b) // Logical Error Danger of similarity between C and mathematic if(a < b < c) // Logical Error if(a && b > 0) // Logical Error

44 ; is a null statement! #include <stdio.h> int main() { int num; printf("enter a number>>"); scanf("%d",&num); if (num>100); printf("this statement always is displayed!"); return 0; }

45 Multiple conditions If-else if-else if-. Select from alternative values of a variable switch-case Values should be constant not expression: i, Values & Variables should be int or char

46 Each switch-case can be rewritten by If-else if-else version of switch-case in the previous slide if(variable == value1)} <statements 1> <statements 2> } else if(variable == value2){ <statements 2> }

47 switch(variable){ case value1: <statements 1> break; case value2: <statements 2> break; default: <statements 3> } If(variable == value1) { <statements 1> } else if(variable == value2) { <statements 2> } else{ <statements 3> }

48 Get the operation (contains +,-,*,/,\) as a character (variable name: op)! Get two input numbers (variable names: num1, num2 ). Compute and display the expression of: num1 (op) num2 + - * /or\

49 Header file: <ctype.h> Function isalnum isalpha iscntrl isdigit isgraph islower isprint ispunct isspace isupper isxdigit tolower toupper Work Of Function Tests whether a character is alphanumeric or not Tests whether a character is aplhabetic or not Tests whether a character is control or not Tests whether a character is digit or not Tests whether a character is grahic or not Tests whether a character is lowercase or not Tests whether a character is printable or not Tests whether a character is punctuation or not Tests whether a character is white space or not Tests whether a character is uppercase or not Tests whether a character is hexadecimal or not Converts to lowercase if the character is in uppercase Converts to uppercase if the character is in lowercase

50 #include <stdio.h> #include <stdlib.h> int main(void){ int res, opd1, opd2; char opr; printf("operand1 : "); scanf("%d", &opd1); printf("operand2 : "); scanf("%d", &opd2); printf("operator : "); scanf(" %c", &opr); switch(opr){ case '+': res = opd1 + opd2; break; case '-': res = opd1 - opd2; break; case '/': res = opd1 / opd2; break;

51 } case '*': res = opd1 * opd2; break; default: printf("invalid operator \n"); return -1; } printf("%d %c %d = %d\n", opd1, opr, opd2, res); return 0;

52 switch(variable){ case value1: case value2: <statements 1> break; case value3: <statements 2> } If( (variable == value1) (variable == value2) ){ <statements 1> } else if (variable == value3) { <statements 2> }

53 if-else is more powerful than switch-case switch-case is only for checking the values of a variable and the values must be constant Some if-else cannot be rewritten by switch-case double var1, var2; if(var1 <= 1.1) <statements 1> if(var1 == var2) <statements 2>

54 bool b; switch (x){ case 0: b = 0; break; case 1: switch(y){ case } } break; //b = x && y case 0: b = 0; break; 1: b = 1; break;

55 All values used in case should be different switch(i){ //Error case 1: case 2: case 1:

56 All values must be value, not expression of variables switch(i){ //Error case j: case 2: case k+10:

57 While Do while For

58 Example: Write a program that read 3 integer and compute average It is easy. 3 scanf, an addition, a division and, a printf Example: Write a program that read 3000 integer and compute average?? 3000 scanf!!! Example: Write a program that read n integer and compute average N??? scanf Repetition in algorithms

59 A loop is a group of instructions the computer executes repeatedly while some loop-continuation condition remains true. We have discussed two means of repetition: Counter-controlled repetition Sentinel-controlled repetition Counter-controlled repetition is sometimes called definite repetition because we know in advance exactly how many times the loop will be executed. Sentinel-controlled repetition is sometimes called indefinite repetition because it s not known in advance how many times the loop will be executed.

60 In counter-controlled repetition, a control variable is used to count the number of repetitions. Counter-controlled repetition requires: The initial value of the control variable. The increment (or decrement) by which the control variable is modified each time through the loop. The condition that tests for the final value of the control variable (i.e., whether looping should continue).

61 When we know the number of iteration Average of 10 number Initialize counter = 0 Initialize other variables While (counter < number of loop repetition) do something (e.g. read input, take sum) counter = counter + 1

62 Consider the following problem statement: A class of ten students took a quiz. The grades (integers in the range 0 to 100) for this quiz are available to you. Determine the class average on the quiz.

63 Sentinel values are used to control repetition when: The precise number of repetitions is not known in advance, and The loop includes statements that obtain data each time the loop is performed. The sentinel is entered after all regular data items have been supplied to the program. Sentinels must be distinct from regular data items.

64 When we do NOT know the number of iteration But we know, when loop terminates E.g. Average of arbitrary positive numbers ending with <0 Get first input as n While (n is not sentinel) do something (sum, ) get the next input as n if (there is not any valid input) else S2 then S1

65 Consider the following problem: Develop a class averaging program that will process an arbitrary number of grades each time the program is run. One way to solve this problem is to use a special value called a sentinel value (also called a signal value, a dummy value, or a flag value) to indicate end of data entry.

66 The user types in grades until all legitimate grades have been entered. The user then types the sentinel value to indicate that the last grade has been entered. Clearly, the sentinel value must be chosen so that it cannot be confused with an acceptable input value.

67

68 Repetition is performed by loops Put all statements to repeat in a loop Don t loop to infinity Stop the repetition Based on some conditions (counter, sentinel) C has 3 statements for loops while statement do-while statement for statement

69 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? YES Process A

70 while ( <expression> ) <statements>

71 <stdio.h> برنامه ای بنویسید که عدد n را از کاربر بگیرد و اعداد 0 تا n را چاپ کند. int main(void){ int n, number; number = 0; printf("enter n: "); scanf("%d", &n); while(number <= n){ printf("%d \n", number); number++; } return 0; }

72 #include <stdio.h> int main(void){ int negative_num, positive_num; int number; negative_num = positive_num = 0; printf("enter Zero to stop \n"); printf("enter next number: "); scanf("%d", &number); while(number!= 0){ if(number > 0) positive_num++; else negative_num++; } printf("enter next number: "); scanf("%d", &number); } printf("the number of positive numbers printf("the number of negative numbers return 0; = %d\n", positive_num); = %d\n", negative_num);

73 Consider a program segment designed to find the first power of 3 larger than 100. When the following while repetition statement finishes executing, product will contain the desired answer: product = 3; while ( product <= 100 ) { product = 3 * product; } /* end while */

74 do <statements> while (<expression>);

75 #include <stdio.h> int main(void){ int n; double number, sum; printf("enter n > 0: "); scanf("%d", &n); if(n < 1){printf("wrong input"); return -1;} sum = 0; number = 0.0; do{ number++; sum += number / (number + 1.0); }while(number < n); printf("sum = %f\n", sum); return 0; }

76 #include <stdio.h> int main(void){ int negative_num=0, positive_num=0; int number; printf("enter Zero to stop \n"); do{ printf("enter next number: "); scanf("%d", &number); if(number > 0) positive_num++; else if(number < 0) negative_num++; }while(number!= 0); printf("the number of positive printf("the number of negative return 0; numbers numbers = %d\n", positive_num); = %d\n", negative_num); }

77 for(<expression1>;<expression2>; <expression3>) <statements>

78 counter 1, sum 0 false counter < 6 true input n sum sum + n counter++ output sum int x, sum, i; sum = 0; for (i = 1; i < 6; i++) { scanf( %d,&x); sum = sum + x; } printf( %d,sum);

79 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

80 Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); num 1 _

81 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); 1 _

82 Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); num 1 1 _

83 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); 2 1 _

84 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); 2 1 _

85 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

86 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

87 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

88 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

89 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

90 num Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); _

91 4 Example: for (num = 1; num <= 3; num++ ) printf( %d\t, num); printf( have come to exit\n ); have come to exit_

92 int grade, count, i; double average, sum; sum = 0; printf("enter the number of students: "); scanf("%d", &count); for(i = 0; i < count; i++){ printf("enter the grade of %d-th student: scanf("%d", &grade); sum += grade; ", (i + 1)); } average = sum / count; printf("the average of your class is %0.3f\n", average); return 0; }

93 int n, number; printf("enter n: "); scanf("%d", &n); for(number = 1; number <= n; number++) if((number % 2) == 0) printf("%d \n", number); } return 0;

94 int n, number; printf("enter n: "); scanf("%d", &n); for(number = 2; number <= n; number += 2) printf("%d \n", number); } return 0;

95 The following examples show methods of varying the control variable in a for statement. Vary the control variable from 1 to 100 in increments of 1. for ( i = 1; i <= 100; i++ ) Vary the control variable from 100 to 1 in increments of -1 (decrements of 1). for ( i = 100; i >= 1; i-- ) Vary the control variable from 7 to 77 in steps of 7. for ( i = 7; i <= 77; i += 7 ) Vary the control variable from 20 to 2 in steps of -2. for ( i = 20; i >= 2; i -= 2 ) Vary the control variable over the following sequence of values: 2, 5, 8, 11, 14, 17. for ( j = 2; j <= 17; j += 3 ) Vary the control variable over the following sequence of values: 44, 33, 22, 11, 0. for ( j = 44; j >= 0; j -= 11 )

96 Expression1 and Expression3 can be any number of expressions for(i = 0, j = 0; i < 10; i++, j--) Expression2 at most should be a single expression for(i = 0, j = 0; i < 10, j > -100; i++, j--) //ERROR Any expression can be empty expression for(;i<10;t++) for(;;)//infinite loop

97 The three expressions in the for statement are optional. for(;;) One may omit expression1 if the control variable is initialized elsewhere in the program. If expression2 is omitted, C assumes that the condition is true, thus creating an infinite loop. expression3 may be omitted if the increment is calculated by statements in the body of the for statement or if no increment is needed.

98 <statement> in loops can be empty while(<expression>) ; E.g., while(i++ <= n) ; for(<expression1>; <expression2>;<expression3>); E.g., for(i = 0; i < 10; printf("%d\n",i), i++) ;

99 <statement> in loops can be loop itself while(<expression0>) for(<expression1>; <expression2>;<expression3>) <statements> for(<expression1>; <expression2>;<expression3>) do <statements> while(<expression>);

100 A program that takes n and m and prints ***.* (m * in each line) ***.* ***.* (n lines)

101 int main(void){ int i, j, n, m; printf("enter n & scanf("%d%d", &n, m: "); &m); for(i = 0; i < n; i++){ for(j = 0; j < m; j++) printf("*"); } printf("\n"); } return 0;

102 A program that takes n and prints * ** *** (i * in i-th line) ***.* (n lines)

103 #include <stdio.h> int main(void){ int i, j, n; printf("enter n: "); scanf("%d", &n); i = 1; while(i <= n){ for(j = 0; j < i; j++) printf("*"); printf("\n"); i++; } return 0; }

104 A program that takes a number and generates the following pattern Input = 5 * * ** *** **** ***** **** *** ** for(i= 1; i <= n; i++){ for(j= 0; j < i-1;j++) printf(" "); for(j= 1; j <= i; j++) printf("*"); printf("\n"); } for(i=n-1; i >= 1; i--){ for(j= 1; j < i; j++) printf(" "); for(j = 1; j <= i; j++) printf("*"); printf("\n"); }

105 The break and continue statements are used to alter the flow of control. The break statement, when executed in a while, for, do while or switch statement, causes an immediate exit from that statement. Program execution continues with the next statement.

106 Exit from loop based on some conditions do{ scanf("%d", &a); scanf("%d", &b); if(b == 0) break; res = a / b; printf("a /= %d\n", res); }while(b > 0);

107

108 int i,j; for(i=1; i<6;i++){ for(j =1; j<6;j++) { printf("%d %d\n", i,j); if(j==3) break; } }

109

110 int n, i, flag = 0; printf("enter a positive integer: "); scanf("%d",&n); for(i=2; i<=sqrt(n); ++i) { if(!n%i) { flag=1; break; } } if (!flag) printf("%d is a prime number.",n); else printf("%d is not a prime number.",n);

111 Jump to end of loop and continue repetition The continue statement, when executed in a while, for or do while statement, skips the remaining statements in the body of that control statement and performs the next iteration of the loop. do{ scanf("%f", &a); scanf("%f", &b); if(b == 0) continue; res = a / b; }while(a> 0); printf("a / b= %f\n", res);

112

113 When you know the number of repetition Counter-controlled loops Usually, for statements When you don t know the number of repetitions (sentinel loop) Some condition should be check before starting loop Usually, while statement The loop should be executed at least one time Usually, do-while statement

114 Loop should terminate E.g., in for loops, after each iteration, we should approach to the stop condition for(i = 0; i < 10; i++) //OK for(i = 0; i < 10; i--) //Bug Initialize loop control variables int i; for( ; i < 10; i++) //Bug

115 Don t modify forloop controller in loop body for(i = 0; i < 10; i++){... i--; //Bug } Take care about wrong control conditions < vs. <= = vs. == int b = 10; while(a = b){//it means while(true) scanf("%d",&a) {

ALGORITHMS AND FLOWCHARTS

ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution of problem

More information

PSEUDOCODE AND FLOWCHARTS. Introduction to Programming

PSEUDOCODE AND FLOWCHARTS. Introduction to Programming PSEUDOCODE AND FLOWCHARTS Introduction to Programming What s Pseudocode? Artificial and Informal language Helps programmers to plan an algorithm Similar to everyday English Not an actual programming language

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Lecture 6: Making Decisions What We Will Learn Introduction Conditions and Boolean operations if-else statement switch-case statement Conditional expressions 2 What We Will

More information

Computer System and programming in C

Computer System and programming in C Approaches to Problem Solving Concept of algorithm and flow charts ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence

More information

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving

CS 199 Computer Programming. Spring 2018 Lecture 2 Problem Solving CS 199 Computer Programming Spring 2018 Lecture 2 Problem Solving ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence

More information

Class 8 ALGORITHMS AND FLOWCHARTS. The City School

Class 8 ALGORITHMS AND FLOWCHARTS. The City School Class 8 ALGORITHMS AND FLOWCHARTS ALGORITHMS AND FLOWCHARTS A typical programming task can be divided into two phases: Problem solving phase produce an ordered sequence of steps that describe solution

More information

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving

CS111: PROGRAMMING LANGUAGE1. Lecture 2: Algorithmic Problem Solving CS111: PROGRAMMING LANGUAGE1 Lecture 2: Algorithmic Problem Solving Agenda 2 Problem Solving Techniques Pseudocode Algorithm Flow charts Examples How People Solve Problems 3 A Problem exists when what

More information

Fundamental of Programming (C)

Fundamental of Programming (C) Borrowed from lecturer notes by Omid Jafarinezhad Fundamental of Programming (C) Lecturer: Vahid Khodabakhshi Lecture 5 Structured Program Development Department of Computer Engineering How to develop

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Lecture 5 - Structured Program Development Lecturer : Ebrahim Jahandar Borrowed from lecturer notes by Omid Jafarinezhad How to develop a program? Requirements Problem Analysis

More information

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1

CSE123 LECTURE 3-1. Program Design and Control Structures Repetitions (Loops) 1-1 CSE123 LECTURE 3-1 Program Design and Control Structures Repetitions (Loops) 1-1 The Essentials of Repetition Loop Group of instructions computer executes repeatedly while some condition remains true Counter-controlled

More information

CSC 121 Spring 2017 Howard Rosenthal

CSC 121 Spring 2017 Howard Rosenthal CSC 121 Spring 2017 Howard Rosenthal Agenda To be able to define computer program, algorithm, and highlevel programming language. To be able to list the basic stages involved in writing a computer program.

More information

UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS

UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS UNDERSTANDING PROBLEMS AND HOW TO SOLVE THEM BY USING COMPUTERS INTRODUCTION TO PROBLEM SOLVING Introduction to Problem Solving Understanding problems Data processing Writing an algorithm CONTINUE.. Tool

More information

Branching is deciding what actions to take and Looping is deciding how many times to take a certain action.

Branching is deciding what actions to take and Looping is deciding how many times to take a certain action. 3.0 Control Statements in C Statements The statements of a C program control the flow of program execution. A statement is a command given to the computer that instructs the computer to take a specific

More information

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University

ITC213: STRUCTURED PROGRAMMING. Bhaskar Shrestha National College of Computer Studies Tribhuvan University ITC213: STRUCTURED PROGRAMMING Bhaskar Shrestha National College of Computer Studies Tribhuvan University Lecture 08: Control Statements Readings: Chapter 6 Control Statements and Their Types A control

More information

MODULE 2: Branching and Looping

MODULE 2: Branching and Looping MODULE 2: Branching and Looping I. Statements in C are of following types: 1. Simple statements: Statements that ends with semicolon 2. Compound statements: are also called as block. Statements written

More information

Chapter 3 Structured Program Development

Chapter 3 Structured Program Development 1 Chapter 3 Structured Program Development Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. Chapter 3 - Structured Program Development Outline 3.1 Introduction

More information

Syntax of for loop is as follows: for (inite; terme; updatee) { block of statements executed if terme is true;

Syntax of for loop is as follows: for (inite; terme; updatee) { block of statements executed if terme is true; Birla Institute of Technology & Science, Pilani Computer Programming (CSF111) Lab-5 ---------------------------------------------------------------------------------------------------------------------------------------------

More information

Subject: PIC Chapter 2.

Subject: PIC Chapter 2. 02 Decision making 2.1 Decision making and branching if statement (if, if-, -if ladder, nested if-) Switch case statement, break statement. (14M) 2.2 Decision making and looping while, do, do-while statements

More information

Structured Program Development in C

Structured Program Development in C 1 3 Structured Program Development in C 3.2 Algorithms 2 Computing problems All can be solved by executing a series of actions in a specific order Algorithm: procedure in terms of Actions to be executed

More information

Introduction. C provides two styles of flow control:

Introduction. C provides two styles of flow control: Introduction C provides two styles of flow control: Branching Looping Branching is deciding what actions to take and looping is deciding how many times to take a certain action. Branching constructs: if

More information

Structured Program Development

Structured Program Development Structured Program Development Chih-Wei Tang ( 唐之瑋 ) Department of Communication Engineering National Central University JhongLi, Taiwan Outline Introduction The selection statement if if.else switch The

More information

ECE15: Introduction to Computer Programming Using the C Language. Lecture Unit 4: Flow of Control

ECE15: Introduction to Computer Programming Using the C Language. Lecture Unit 4: Flow of Control ECE15: Introduction to Computer Programming Using the C Language Lecture Unit 4: Flow of Control Outline of this Lecture Examples of Statements in C Conditional Statements The if-else Conditional Statement

More information

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE

PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE PROGRAMMING IN C LAB MANUAL FOR DIPLOMA IN ECE/EEE 1. Write a C program to perform addition, subtraction, multiplication and division of two numbers. # include # include int a, b,sum,

More information

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types

Muntaser Abulafi Yacoub Sabatin Omar Qaraeen. C Data Types Programming Fundamentals for Engineers 0702113 5. Basic Data Types Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 2 C Data Types Variable definition C has a concept of 'data types' which are used to define

More information

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from

INTRODUCTION TO C++ PROGRAM CONTROL. Dept. of Electronic Engineering, NCHU. Original slides are from INTRODUCTION TO C++ PROGRAM CONTROL Original slides are from http://sites.google.com/site/progntut/ Dept. of Electronic Engineering, NCHU Outline 2 Repetition Statement for while do.. while break and continue

More information

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3).

cs3157: another C lecture (mon-21-feb-2005) C pre-processor (3). cs3157: another C lecture (mon-21-feb-2005) C pre-processor (1). today: C pre-processor command-line arguments more on data types and operators: booleans in C logical and bitwise operators type conversion

More information

Chapter 3 Structured Program Development in C Part II

Chapter 3 Structured Program Development in C Part II Chapter 3 Structured Program Development in C Part II C How to Program, 8/e, GE 2016 Pearson Education, Ltd. All rights reserved. 1 3.7 The while Iteration Statement An iteration statement (also called

More information

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II)

Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II) Introduction to Computing Lecture 07: Repetition and Loop Statements (Part II) Assist.Prof.Dr. Nükhet ÖZBEK Ege University Department of Electrical & Electronics Engineering nukhet.ozbek@ege.edu.tr Topics

More information

Flow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch

Flow of Control. Selection. if statement. True and False in C False is represented by any zero value. switch Flow of Control True and False in C Conditional Execution Iteration Nested Code(Nested-ifs, Nested-loops) Jumps 1 True and False in C False is represented by any zero value The int expression having the

More information

Fundamentals of Computer Programming Using C

Fundamentals of Computer Programming Using C CHARUTAR VIDYA MANDAL S SEMCOM Vallabh Vidyanagar Faculty Name: Ami D. Trivedi Class: FYBCA Subject: US01CBCA01 (Fundamentals of Computer Programming Using C) *UNIT 3 (Structured Programming, Library Functions

More information

CS3157: Advanced Programming. Outline

CS3157: Advanced Programming. Outline CS3157: Advanced Programming Lecture #8 Feb 27 Shlomo Hershkop shlomo@cs.columbia.edu 1 Outline More c Preprocessor Bitwise operations Character handling Math/random Review for midterm Reading: k&r ch

More information

Module 4: Decision-making and forming loops

Module 4: Decision-making and forming loops 1 Module 4: Decision-making and forming loops 1. Introduction 2. Decision making 2.1. Simple if statement 2.2. The if else Statement 2.3. Nested if Statement 3. The switch case 4. Forming loops 4.1. The

More information

Chapter 8 - Characters and Strings

Chapter 8 - Characters and Strings 1 Chapter 8 - Characters and Strings Outline 8.1 Introduction 8.2 Fundamentals of Strings and Characters 8.3 Character Handling Library 8.4 String Conversion Functions 8.5 Standard Input/Output Library

More information

DECISION CONTROL AND LOOPING STATEMENTS

DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL AND LOOPING STATEMENTS DECISION CONTROL STATEMENTS Decision control statements are used to alter the flow of a sequence of instructions. These statements help to jump from one part of

More information

Unit 3 Decision making, Looping and Arrays

Unit 3 Decision making, Looping and Arrays Unit 3 Decision making, Looping and Arrays Decision Making During programming, we have a number of situations where we may have to change the order of execution of statements based on certain conditions.

More information

Decision Making and Loops

Decision Making and Loops Decision Making and Loops Goals of this section Continue looking at decision structures - switch control structures -if-else-if control structures Introduce looping -while loop -do-while loop -simple for

More information

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION

Unit 5. Decision Making and Looping. School of Science and Technology INTRODUCTION INTRODUCTION Decision Making and Looping Unit 5 In the previous lessons we have learned about the programming structure, decision making procedure, how to write statements, as well as different types of

More information

Dr. R. Z. Khan, Associate Professor, Department of Computer Science

Dr. R. Z. Khan, Associate Professor, Department of Computer Science ALIGARH MUSLIM UNIVERSITY Department of Computer Science Course: CSM-102: Programming & Problem Solving Using C Academic Session 2015-2016 UNIT-2: Handout-3 Topic: Control Structures (Selection & Repetition)

More information

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs

PDS Lab Section 16 Autumn Tutorial 3. C Programming Constructs PDS Lab Section 16 Autumn-2017 Tutorial 3 C Programming Constructs This flowchart shows how to find the roots of a Quadratic equation Ax 2 +Bx+C = 0 Start Input A,B,C x B 2 4AC False x If 0 True B x 2A

More information

Lecture 6. Statements

Lecture 6. Statements Lecture 6 Statements 1 Statements This chapter introduces the various forms of C++ statements for composing programs You will learn about Expressions Composed instructions Decision instructions Loop instructions

More information

Decision Making and Branching

Decision Making and Branching INTRODUCTION Decision Making and Branching Unit 4 In the previous lessons we have learned about the programming structure, data types, declaration of variables, tokens, constants, keywords and operators

More information

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions.

There are algorithms, however, that need to execute statements in some other kind of ordering depending on certain conditions. Introduction In the programs that we have dealt with so far, all statements inside the main function were executed in sequence as they appeared, one after the other. This type of sequencing is adequate

More information

C Programming for Engineers Structured Program

C Programming for Engineers Structured Program C Programming for Engineers Structured Program ICEN 360 Spring 2017 Prof. Dola Saha 1 Switch Statement Ø Used to select one of several alternatives Ø useful when the selection is based on the value of

More information

Decision Making -Branching. Class Incharge: S. Sasirekha

Decision Making -Branching. Class Incharge: S. Sasirekha Decision Making -Branching Class Incharge: S. Sasirekha Branching The C language programs presented until now follows a sequential form of execution of statements. Many times it is required to alter the

More information

Fundamentals of Programming. Lecture 11: C Characters and Strings

Fundamentals of Programming. Lecture 11: C Characters and Strings 1 Fundamentals of Programming Lecture 11: C Characters and Strings Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu Sharif University of Technology Computer Engineering Department The lectures of this

More information

More examples for Control statements

More examples for Control statements More examples for Control statements C language possesses such decision making capabilities and supports the following statements known as control or decision-making statements. 1. if statement 2. switch

More information

today cs3157-fall2002-sklar-lect05 1

today cs3157-fall2002-sklar-lect05 1 today homework #1 due on monday sep 23, 6am some miscellaneous topics: logical operators random numbers character handling functions FILE I/O strings arrays pointers cs3157-fall2002-sklar-lect05 1 logical

More information

Fundamentals of Programming. Lecture 6: Structured Development (part one)

Fundamentals of Programming. Lecture 6: Structured Development (part one) Fundamentals of Programming Lecture 6: Structured Development (part one) Instructor: Fatemeh Zamani f_zamani@ce.sharif.edu edu Sharif University of Technology Computer Engineering Department Outline Algorithms

More information

Control Structure: Loop

Control Structure: Loop Control Structure: Loop Knowledge: Understand the various concepts of loop control structure Skill: Be able to develop a program involving loop control structure 1 Loop Structure Condition is tested first

More information

Statements. Control Flow Statements. Relational Operators. Logical Expressions. Relational Operators. Relational Operators 1/30/14

Statements. Control Flow Statements. Relational Operators. Logical Expressions. Relational Operators. Relational Operators 1/30/14 Statements Control Flow Statements Based on slides from K. N. King Bryn Mawr College CS246 Programming Paradigm So far, we ve used return statements and expression statements. Most of C s remaining statements

More information

COMP 208 Computers in Engineering

COMP 208 Computers in Engineering COMP 208 Computers in Engineering Lecture 14 Jun Wang School of Computer Science McGill University Fall 2007 COMP 208 - Lecture 14 1 Review: basics of C C is case sensitive 2 types of comments: /* */,

More information

REPETITION CONTROL STRUCTURE LOGO

REPETITION CONTROL STRUCTURE LOGO CSC 128: FUNDAMENTALS OF COMPUTER PROBLEM SOLVING REPETITION CONTROL STRUCTURE 1 Contents 1 Introduction 2 for loop 3 while loop 4 do while loop 2 Introduction It is used when a statement or a block of

More information

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section :

CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart Q-2) Explain basic structure of c language Documentation section : CP FAQS Q-1) Define flowchart and explain Various symbols of flowchart ANS. Flowchart:- A diagrametic reperesentation of program is known as flowchart Symbols Q-2) Explain basic structure of c language

More information

Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26

Day06 A. Young W. Lim Wed. Young W. Lim Day06 A Wed 1 / 26 Day06 A Young W. Lim 2017-09-20 Wed Young W. Lim Day06 A 2017-09-20 Wed 1 / 26 Outline 1 Based on 2 C Program Control Overview for, while, do... while break and continue Relational and Logical Operators

More information

CpSc 1111 Lab 4 Formatting and Flow Control

CpSc 1111 Lab 4 Formatting and Flow Control CpSc 1111 Lab 4 Formatting and Flow Control Overview By the end of the lab, you will be able to: use fscanf() to accept a character input from the user and print out the ASCII decimal, octal, and hexadecimal

More information

Unit-II Programming and Problem Solving (BE1/4 CSE-2)

Unit-II Programming and Problem Solving (BE1/4 CSE-2) Unit-II Programming and Problem Solving (BE1/4 CSE-2) Problem Solving: Algorithm: It is a part of the plan for the computer program. An algorithm is an effective procedure for solving a problem in a finite

More information

ECET 264 C Programming Language with Applications. C Program Control

ECET 264 C Programming Language with Applications. C Program Control ECET 264 C Programming Language with Applications Lecture 7 C Program Control Paul I. Lin Professor of Electrical & Computer Engineering Technology http://www.etcs.ipfw.edu/~lin Lecture 7 - Paul I. Lin

More information

Programming for Electrical and Computer Engineers. Loops

Programming for Electrical and Computer Engineers. Loops Programming for Electrical and Computer Engineers Loops Dr. D. J. Jackson Lecture 6-1 Iteration Statements C s iteration statements are used to set up loops. A loop is a statement whose job is to repeatedly

More information

Programming Language A

Programming Language A Programming Language A Takako Nemoto (JAIST) 30 October Takako Nemoto (JAIST) 30 October 1 / 29 From Homework 3 Homework 3 1 Write a program to convert the input Celsius degree temperature into Fahrenheight

More information

Chapter 6. Loops. Iteration Statements. C s iteration statements are used to set up loops.

Chapter 6. Loops. Iteration Statements. C s iteration statements are used to set up loops. Chapter 6 Loops 1 Iteration Statements C s iteration statements are used to set up loops. A loop is a statement whose job is to repeatedly execute some other statement (the loop body). In C, every loop

More information

SELECTION STATEMENTS:

SELECTION STATEMENTS: UNIT-2 STATEMENTS A statement is a part of your program that can be executed. That is, a statement specifies an action. Statements generally contain expressions and end with a semicolon. Statements that

More information

Chapter 13 Control Structures

Chapter 13 Control Structures Chapter 13 Control Structures Control Structures Conditional making a decision about which code to execute, based on evaluated expression if if-else switch Iteration executing code multiple times, ending

More information

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons

Computer Programming. Basic Control Flow - Loops. Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Computer Programming Basic Control Flow - Loops Adapted from C++ for Everyone and Big C++ by Cay Horstmann, John Wiley & Sons Objectives To learn about the three types of loops: while for do To avoid infinite

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU

CSE101-lec#12. Designing Structured Programs Introduction to Functions. Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU CSE101-lec#12 Designing Structured Programs Introduction to Functions Created By: Amanpreet Kaur & Sanjeev Kumar SME (CSE) LPU Outline Designing structured programs in C: Counter-controlled repetition

More information

Computer Programming. Decision Making (2) Loops

Computer Programming. Decision Making (2) Loops Computer Programming Decision Making (2) Loops Topics The Conditional Execution of C Statements (review) Making a Decision (review) If Statement (review) Switch-case Repeating Statements while loop Examples

More information

Loops / Repetition Statements

Loops / Repetition Statements Loops / Repetition Statements Repetition statements allow us to execute a statement multiple times Often they are referred to as loops C has three kinds of repetition statements: the while loop the for

More information

UIC. C Programming Primer. Bharathidasan University

UIC. C Programming Primer. Bharathidasan University C Programming Primer UIC C Programming Primer Bharathidasan University Contents Getting Started 02 Basic Concepts. 02 Variables, Data types and Constants...03 Control Statements and Loops 05 Expressions

More information

CS110D: PROGRAMMING LANGUAGE I

CS110D: PROGRAMMING LANGUAGE I CS110D: PROGRAMMING LANGUAGE I Computer Science department Lecture 5&6: Loops Lecture Contents Why loops?? While loops for loops do while loops Nested control structures Motivation Suppose that you need

More information

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018

Computer Programing. for Physicists [SCPY204] Class 02: 25 Jan 2018 Computer Programing Class 02: 25 Jan 2018 [SCPY204] for Physicists Content: Data, Data type, program control, condition and loop, function and recursion, variable and scope Instructor: Puwis Amatyakul

More information

Computers Programming Course 7. Iulian Năstac

Computers Programming Course 7. Iulian Năstac Computers Programming Course 7 Iulian Năstac Recap from previous course Operators in C Programming languages typically support a set of operators, which differ in the calling of syntax and/or the argument

More information

Introduction to Programming

Introduction to Programming Introduction to Programming Lecture 8: Functions What We Will Learn Introduction Passing input parameters Producing output Scope of variables Storage Class of variables Function usage example Recursion

More information

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved.

C How to Program, 6/e by Pearson Education, Inc. All Rights Reserved. C How to Program, 6/e Before writing a program to solve a particular problem, it s essential to have a thorough understanding of the problem and a carefully planned approach to solving the problem. The

More information

Repetition Structures

Repetition Structures Repetition Structures Chapter 5 Fall 2016, CSUS Introduction to Repetition Structures Chapter 5.1 1 Introduction to Repetition Structures A repetition structure causes a statement or set of statements

More information

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution.

Condition-Controlled Loop. Condition-Controlled Loop. If Statement. Various Forms. Conditional-Controlled Loop. Loop Caution. Repetition Structures Introduction to Repetition Structures Chapter 5 Spring 2016, CSUS Chapter 5.1 Introduction to Repetition Structures The Problems with Duplicate Code A repetition structure causes

More information

COP 3223 Introduction to Programming with C - Study Union - Spring 2018

COP 3223 Introduction to Programming with C - Study Union - Spring 2018 COP 3223 Introduction to Programming with C - Study Union - Spring 2018 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur

Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Problem Solving through Programming In C Prof. Anupam Basu Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur Lecture 18 Switch Statement (Contd.) And Introduction to

More information

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee

C Language Part 2 Digital Computer Concept and Practice Copyright 2012 by Jaejin Lee C Language Part 2 (Minor modifications by the instructor) 1 Scope Rules A variable declared inside a function is a local variable Each local variable in a function comes into existence when the function

More information

Contents. Preface. Introduction. Introduction to C Programming

Contents. Preface. Introduction. Introduction to C Programming c11fptoc.fm Page vii Saturday, March 23, 2013 4:15 PM Preface xv 1 Introduction 1 1.1 1.2 1.3 1.4 1.5 Introduction The C Programming Language C Standard Library C++ and Other C-Based Languages Typical

More information

Introduction to Flowcharting

Introduction to Flowcharting Introduction to Flowcharting 1 Acknowledgment This tutorial is based upon Appendix C from Starting Out with C++: From Control Structures to Objects (5th Edition) Copyright Tony Gaddis 2007 Published by

More information

Chapter 4 C Program Control

Chapter 4 C Program Control 1 Chapter 4 C Program Control Copyright 2007 by Deitel & Associates, Inc. and Pearson Education Inc. All Rights Reserved. 2 Chapter 4 C Program Control Outline 4.1 Introduction 4.2 The Essentials of Repetition

More information

COP 2000 Introduction to Computer Programming Mid-Term Exam Review

COP 2000 Introduction to Computer Programming Mid-Term Exam Review he exam format will be different from the online quizzes. It will be written on the test paper with questions similar to those shown on the following pages. he exam will be closed book, but students can

More information

BBM 101 Introduc/on to Programming I Fall 2014, Lecture 5. Aykut Erdem, Erkut Erdem, Fuat Akal

BBM 101 Introduc/on to Programming I Fall 2014, Lecture 5. Aykut Erdem, Erkut Erdem, Fuat Akal BBM 101 Introduc/on to Programming I Fall 2014, Lecture 5 Aykut Erdem, Erkut Erdem, Fuat Akal 1 Today Itera/on Control Loop Statements for, while, do- while structures break and con/nue Some simple numerical

More information

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); }

C Program. Output. Hi everyone. #include <stdio.h> main () { printf ( Hi everyone\n ); } C Program Output #include main () { printf ( Hi everyone\n ); Hi everyone #include main () { printf ( Hi everyone\n ); #include and main are Keywords (or Reserved Words) Reserved Words

More information

Method & Tools for Program Analysis & Design

Method & Tools for Program Analysis & Design Method & Tools for Program Analysis & Design TMB208 Pemrograman Teknik Kredit: 3 (2-3) 1 Programming Logic and Design, Introductory, Fourth Edition 2 1 Programming Methods Based on structures of programming

More information

Flow Chart. The diagrammatic representation shows a solution to a given problem.

Flow Chart. The diagrammatic representation shows a solution to a given problem. low Charts low Chart A flowchart is a type of diagram that represents an algorithm or process, showing the steps as various symbols, and their order by connecting them with arrows. he diagrammatic representation

More information

COP 3223 Introduction to Programming with C - Study Union - Fall 2017

COP 3223 Introduction to Programming with C - Study Union - Fall 2017 COP 3223 Introduction to Programming with C - Study Union - Fall 2017 Chris Marsh and Matthew Villegas Contents 1 Code Tracing 2 2 Pass by Value Functions 4 3 Statically Allocated Arrays 5 3.1 One Dimensional.................................

More information

Informatica e Sistemi in Tempo Reale

Informatica e Sistemi in Tempo Reale Informatica e Sistemi in Tempo Reale Introduction to C programming Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa October 5, 2011 G. Lipari (Scuola Superiore Sant Anna) Introduction

More information

Decisions. Arizona State University 1

Decisions. Arizona State University 1 Decisions CSE100 Principles of Programming with C++, Fall 2018 (based off Chapter 4 slides by Pearson) Ryan Dougherty Arizona State University http://www.public.asu.edu/~redoughe/ Arizona State University

More information

Sudeshna Sarkar Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur

Sudeshna Sarkar Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Programming and Data Structure Sudeshna Sarkar Dept. of Computer Science & Engineering. Indian Institute of Technology Kharagpur Shortcuts in Assignment Statements A+=C A=A+C A-=B A=A-B A*=D A=A*D A/=E

More information

Introduction. Pretest and Posttest Loops. Basic Loop Structures ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science

Introduction. Pretest and Posttest Loops. Basic Loop Structures ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science 204111 ว ทยาการคอมพ วเตอร เบ องต น Fundamentals of Computer Science ภาคการศ กษาท ภาคการศกษาท 1 ป ปการศกษา การศ กษา 2556 4. การเข ยนโปรแกรมพ นฐาน 4.5 โครงสร างควบค มแบบท าซ า รวบรวมโดย อ. ดร. อาร ร ตน ตรงร

More information

Fundamentals of Programming

Fundamentals of Programming Fundamentals of Programming Introduction to the C language Giuseppe Lipari http://retis.sssup.it/~lipari Scuola Superiore Sant Anna Pisa February 29, 2012 G. Lipari (Scuola Superiore Sant Anna) The C language

More information

CS1100 Introduction to Programming

CS1100 Introduction to Programming Decisions with Variables CS1100 Introduction to Programming Selection Statements Madhu Mutyam Department of Computer Science and Engineering Indian Institute of Technology Madras Course Material SD, SB,

More information

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5)

Midterm Exam. CSCI 2132: Software Development. March 4, Marks. Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5) Banner number: Name: Midterm Exam CSCI 2132: Software Development March 4, 2019 Marks Question 1 (10) Question 2 (10) Question 3 (10) Question 4 (10) Question 5 (5) Question 6 (5) Total (50) Instructions:

More information

Lecture 10. Daily Puzzle

Lecture 10. Daily Puzzle Lecture 10 Daily Puzzle Imagine there is a ditch, 10 feet wide, which is far too wide to jump. Using only eight narrow planks, each no more than 9 feet long, construct a bridge across the ditch. Daily

More information

Lab 2: Structured Program Development in C

Lab 2: Structured Program Development in C Lab 2: Structured Program Development in C (Part A: Your first C programs - integers, arithmetic, decision making, Part B: basic problem-solving techniques, formulating algorithms) Learning Objectives

More information

Multiple Choice Questions ( 1 mark)

Multiple Choice Questions ( 1 mark) Multiple Choice Questions ( 1 mark) Unit-1 1. is a step by step approach to solve any problem.. a) Process b) Programming Language c) Algorithm d) Compiler 2. The process of walking through a program s

More information

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting

CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting CpSc 1111 Lab 4 Part a Flow Control, Branching, and Formatting Your factors.c and multtable.c files are due by Wednesday, 11:59 pm, to be submitted on the SoC handin page at http://handin.cs.clemson.edu.

More information

do, while and for Constructs

do, while and for Constructs Programming Fundamentals for Engineers 0702113 4. Loops do, while and for Constructs Muntaser Abulafi Yacoub Sabatin Omar Qaraeen 1 Loops A loop is a statement whose job is to repeatedly execute some other

More information

3 The L oop Control Structure

3 The L oop Control Structure 3 The L oop Control Structure Loops The while Loop Tips and Traps More Operators The for Loop Nesting of Loops Multiple Initialisations in the for Loop The Odd Loop The break Statement The continue Statement

More information