Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Problem SolvingS1.2.1 Bina © 1998 Liran & Ofir Introduction to Problem Solving Programming in C.

Similar presentations


Presentation on theme: "Introduction to Problem SolvingS1.2.1 Bina © 1998 Liran & Ofir Introduction to Problem Solving Programming in C."— Presentation transcript:

1 Introduction to Problem SolvingS1.2.1 Bina © 1998 Liran & Ofir Introduction to Problem Solving Programming in C

2 Introduction to Problem SolvingS1.2.2 Bina © 1998 Liran & Ofir Problem Solving l Describe the steps that the computer should take in order to solve the problem should take in order to solve the problem n How to get the computer solve a problem? Algorithm

3 Introduction to Problem SolvingS1.2.3 Bina © 1998 Liran & Ofir Steps of Problem Solving 1. Understand the problem to be solved Analysis 2. Devise a solution to the problem Algorithm Design

4 Introduction to Problem SolvingS1.2.4 Bina © 1998 Liran & Ofir Steps of Problem Solving 3. Verify that the solution is correct Desk check 4. Describe the solution using a programming language language Programming

5 Introduction to Problem SolvingS1.2.5 Bina © 1998 Liran & Ofir Steps of Problem Solving 5. Verify that the program does state the solution correctly solution correctly Testing

6 Introduction to Problem SolvingS1.2.6 Bina © 1998 Liran & Ofir Understand the problem n What is the problem? n What are the inputs? n What are the outputs? n What are examples of input output relationships?

7 Introduction to Problem SolvingS1.2.7 Bina © 1998 Liran & Ofir Understand the problem n What is the problem? l Compute the average of 3 numbers

8 Introduction to Problem SolvingS1.2.8 Bina © 1998 Liran & Ofir Understand the problem n What are the inputs? l Input: 3 values

9 Introduction to Problem SolvingS1.2.9 Bina © 1998 Liran & Ofir Understand the problem n What are the outputs l Output: The average of the input values

10 Introduction to Problem SolvingS1.2.10 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3.1 5.3 1.2 Output: 3.2

11 Introduction to Problem SolvingS1.2.11 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 8.1 2.2 1.3 Output: 3.86

12 Introduction to Problem SolvingS1.2.12 Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to calculate the average of 3 values? Step 1. Accept the input values Computer

13 Introduction to Problem SolvingS1.2.13 Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to calculate the average of 3 values? Step 1. Accept the input values Step 2. Compute the average Computer Compute the Average

14 Introduction to Problem SolvingS1.2.14 Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to calculate the average of 3 values? Compute the Average Step 3. Display the average Step 1. Accept the input values Step 2. Compute the average

15 Introduction to Problem SolvingS1.2.15 Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2 Step 3. Display the average Step 1. Accept the input values Step 2. Compute the average Step 2.1. Add up the three values Step 2.2. Divide the result by 3

16 Introduction to Problem SolvingS1.2.16 Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2.1 Step 2.1. Add up the three values l Let “A” denote the first value l Let “B” denote the second value l Let “C” denote the third value l Let “Sum” denote the sum of “A”, “B”, and “C” Sum = A + B + C;

17 Introduction to Problem SolvingS1.2.17 Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2.2 Step 2.1. Divide the result by 3 l Let “Average” denote the average of “A”, “B” and “C” Average = Sum / 3.0;

18 Introduction to Problem SolvingS1.2.18 Bina © 1998 Liran & Ofir Verify that the solution is correct A Step 1. Accept the input values, A, B, C 3.9 B 4.1 C 1.3 Step 3. Display the average Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0;

19 Introduction to Problem SolvingS1.2.19 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; C B A 3.9 4.1 1.3

20 Introduction to Problem SolvingS1.2.20 Bina © 1998 Liran & Ofir Sum Verify that the solution is correct Step 3. Display the average 9.3 Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; C B A 3.9 4.1 1.3

21 Introduction to Problem SolvingS1.2.21 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Average Sum C B A 3.9 4.1 1.3 9.3 3.1

22 Introduction to Problem SolvingS1.2.22 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Average Sum C B A 3.9 4.1 1.3 9.3 3.1 Average is 3.1

23 Introduction to Problem SolvingS1.2.23 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; float A,B,C; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

24 Introduction to Problem SolvingS1.2.24 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; float A,B,C; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

25 Introduction to Problem SolvingS1.2.25 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Sum = A + B + C; float A,B,C; float Sum; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

26 Introduction to Problem SolvingS1.2.26 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; Average = Sum / 3.0; Sum = A + B + C; float A,B,C; float Sum; float Average; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

27 Introduction to Problem SolvingS1.2.27 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 3. Display the average Step 1. Accept the input values, A, B, C Step 2. Compute the average Step 2.1. Sum = A + B + C; Step 2.2. Average = Sum /3.0; printf(“%f”,Average); Average = Sum / 3.0; Sum = A + B + C; float A,B,C; float Sum; float Average; scanf(“%f”,&A); scanf(“%f”,&B); scanf(“%f”,&C);

28 Introduction to Problem SolvingS1.2.28 Bina © 1998 Liran & Ofir Verify that the program does state the solution correctly n Enter the program n Compile n Run n Compare the output to expected output

29 Introduction to Problem SolvingS1.2.29 Bina © 1998 Liran & Ofir SelectionSelection n Facilitates the selection of one of a number of various alternatives based on a condition. If the door is open Then Enter the room Else Knock at the door

30 Introduction to Problem SolvingS1.2.30 Bina © 1998 Liran & Ofir Understand the problem l Accept two integer values and decide whether or not the larger number is divisible by the or not the larger number is divisible by the smaller number smaller number n What is the problem?

31 Introduction to Problem SolvingS1.2.31 Bina © 1998 Liran & Ofir Understand the problem n What are the inputs? l Input: 2 Integer Values

32 Introduction to Problem SolvingS1.2.32 Bina © 1998 Liran & Ofir Understand the problem l Output: Yes n What are the outputs If the larger number is divisible by the second number l Output: No If the larger number is not divisible by the second number

33 Introduction to Problem SolvingS1.2.33 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 4 2 Output: Yes

34 Introduction to Problem SolvingS1.2.34 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3 12 Output: Yes

35 Introduction to Problem SolvingS1.2.35 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3 7 Output: No

36 Introduction to Problem SolvingS1.2.36 Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to decide whether or not the larger number is divisible by the or not the larger number is divisible by the smaller number? smaller number? Step 1. Accept the input values Computer

37 Introduction to Problem SolvingS1.2.37 Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to decide whether or not the larger number is divisible by the or not the larger number is divisible by the smaller number? smaller number? Compute the result Step 1. Accept the input values Step 2. Compute and display the result the result

38 Introduction to Problem SolvingS1.2.38 Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2. Step 2. Compute and display the result l Let “A” denote the first value l Let “B” denote the second value l Let “Larger” denote the larger value l Let “Smaller” denote the smaller value

39 Introduction to Problem SolvingS1.2.39 Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2. Step 2.1. If Larger is divisible by Smaller Then print “Yes” Then print “Yes” Otherwise, Larger is not divisible Otherwise, Larger is not divisible by Smaller and print “No” by Smaller and print “No” Step 2. Compute and display the result

40 Introduction to Problem SolvingS1.2.40 Bina © 1998 Liran & Ofir A Verify that the solution is correct 4 B 2 Step 1. Accept the input values, A, B Step 2. Compute and display the result Smaller Larger Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

41 Introduction to Problem SolvingS1.2.41 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A 2 4 2 4 Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

42 Introduction to Problem SolvingS1.2.42 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A 2 4 2 4 Step 2. Compute and display the result Output: Yes Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

43 Introduction to Problem SolvingS1.2.43 Bina © 1998 Liran & Ofir A Verify that the solution is correct 3 B 12 Step 1. Accept the input values, A, B Step 2. Compute and display the result Smaller Larger Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

44 Introduction to Problem SolvingS1.2.44 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A 12 3 3 Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

45 Introduction to Problem SolvingS1.2.45 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A 12 3 3 Step 2. Compute and display the result Output: Yes Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

46 Introduction to Problem SolvingS1.2.46 Bina © 1998 Liran & Ofir A Verify that the solution is correct 3 B 7 Step 1. Accept the input values, A, B Step 2. Compute and display the result Smaller Larger Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

47 Introduction to Problem SolvingS1.2.47 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A 7 7 3 3 Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

48 Introduction to Problem SolvingS1.2.48 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 1. Accept the input values, A, B Smaller Larger B A 7 7 3 3 Step 2. Compute and display the result Output: No Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No”

49 Introduction to Problem SolvingS1.2.49 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 1. Accept the input values, A, B Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No” int a,b; scanf(“%d”,&a); scanf(“%d”,&b);

50 Introduction to Problem SolvingS1.2.50 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 1. Accept the input values, A, B Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No” if (a > b) { largest = a; largest = a; smallest = b; smallest = b; } else { largest = b; largest = b; smallest = a; smallest = a;} int a,b; int largest,smallest scanf(“%d”,&a); scanf(“%d”,&b);

51 Introduction to Problem SolvingS1.2.51 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 1. Accept the input values, A, B Step 2. Compute and display the result Step 2.1. If Larger is divisible by Smaller Then print “Yes” Smaller Then print “Yes” Otherwise, Larger is not Otherwise, Larger is not divisible by Smaller and divisible by Smaller and print “No” print “No” If (largest % smallest == 0) printf(“Yes”); printf(“Yes”); else printf(“No”); printf(“No”); if (a > b) { largest = a; largest = a; smallest = b; smallest = b; } else { largest = b; largest = b; smallest = a; smallest = a;} int a,b; int largest,smallest scanf(“%d”,&a); scanf(“%d”,&b);

52 Introduction to Problem SolvingS1.2.52 Bina © 1998 Liran & Ofir IterationIteration n Facilitates the repeated execution of a segment of the program. l While you are hungry l Buy a sandwich l Eat the sandwich l While you haven’t read the last slide l Read the next slide

53 Introduction to Problem SolvingS1.2.53 Bina © 1998 Liran & Ofir Understand the problem n What is the problem? l Accept an Integer, N as input and print the value of 1+ 2+ … + N value of 1+ 2+ … + N

54 Introduction to Problem SolvingS1.2.54 Bina © 1998 Liran & Ofir Understand the problem n What are the inputs? l Input: one integer value, N

55 Introduction to Problem SolvingS1.2.55 Bina © 1998 Liran & Ofir Understand the problem n What are the outputs l Output: 1 + 2 + … + N

56 Introduction to Problem SolvingS1.2.56 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 3 Output: 6

57 Introduction to Problem SolvingS1.2.57 Bina © 1998 Liran & Ofir Understand the problem n Input output relationship Input: 4 Output: 10

58 Introduction to Problem SolvingS1.2.58 Bina © 1998 Liran & Ofir Devise a solution to the problem n How is the computer to print the value of 1+ 2+ … + N Step 1. Accept the input value Step 2. Compute the sum Step 3. Display the sum

59 Introduction to Problem SolvingS1.2.59 Bina © 1998 Liran & Ofir Devise a solution to the problem n Refine Step 2 Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.1. Count = 1; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.3.2. Count = Count +1;

60 Introduction to Problem SolvingS1.2.60 Bina © 1998 Liran & Ofir Verify that the solution is correct Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum N 3 Step 2.1. Sum = 0; Step 2.1. Count = 1; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.3.2. Count = Count +1;

61 Introduction to Problem SolvingS1.2.61 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1;

62 Introduction to Problem SolvingS1.2.62 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 0 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1;

63 Introduction to Problem SolvingS1.2.63 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 0 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 1

64 Introduction to Problem SolvingS1.2.64 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 0 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 1

65 Introduction to Problem SolvingS1.2.65 Bina © 1998 Liran & Ofir Sum 0 1 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 1

66 Introduction to Problem SolvingS1.2.66 Bina © 1998 Liran & Ofir 1 Sum 1 2 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count

67 Introduction to Problem SolvingS1.2.67 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 1 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 2

68 Introduction to Problem SolvingS1.2.68 Bina © 1998 Liran & Ofir Sum 1 3 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 2

69 Introduction to Problem SolvingS1.2.69 Bina © 1998 Liran & Ofir 2 Sum 3 3 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count

70 Introduction to Problem SolvingS1.2.70 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 3

71 Introduction to Problem SolvingS1.2.71 Bina © 1998 Liran & Ofir Sum 3 6 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 3

72 Introduction to Problem SolvingS1.2.72 Bina © 1998 Liran & Ofir 3 Sum 6 4 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count

73 Introduction to Problem SolvingS1.2.73 Bina © 1998 Liran & Ofir Verify that the solution is correct N 3 Sum 6 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 4

74 Introduction to Problem SolvingS1.2.74 Bina © 1998 Liran & Ofir Sum 0 6 Verify that the solution is correct N 3 Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.3.1. Sum = Sum + Count; Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; Count 4 6

75 Introduction to Problem SolvingS1.2.75 Bina © 1998 Liran & Ofir Step 2.3.1. Sum = Sum + Count; Describe the solution using a programming language Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; int n; scanf(“%d”,&n);

76 Introduction to Problem SolvingS1.2.76 Bina © 1998 Liran & Ofir Describe the solution using a programming language int sum; int n; sum = 0; Step 2.3.1. Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; scanf(“%d”,&n);

77 Introduction to Problem SolvingS1.2.77 Bina © 1998 Liran & Ofir Describe the solution using a programming language count = 1; Step 2.3.1. Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; int count; int n; int sum; sum = 0; scanf(“%d”,&n);

78 Introduction to Problem SolvingS1.2.78 Bina © 1998 Liran & Ofir Describe the solution using a programming language While (count <= n){ } Step 2.3.1. Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n);

79 Introduction to Problem SolvingS1.2.79 Bina © 1998 Liran & Ofir Describe the solution using a programming language sum = sum+count; sum = sum+count; Step 2.3.1. Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; While (count <= n){ } count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n);

80 Introduction to Problem SolvingS1.2.80 Bina © 1998 Liran & Ofir Describe the solution using a programming language Step 2.3.1. Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; sum = sum+count; sum = sum+count; } While (count <= n){ count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n); count = count +1;

81 Introduction to Problem SolvingS1.2.81 Bina © 1998 Liran & Ofir Describe the solution using a programming language printf(“%d”,sum); Step 2.3.1. Sum = Sum + Count; Step 3. Display the sum Step 1. Accept the input value Step 2. Compute the sum Step 2.1. Sum = 0; Step 2.3. Repeat steps 2.3.1 - 2.3.2 N times Step 2.1. Count = 1; Step 2.3.2. Count = Count +1; sum = sum+count; sum = sum+count; count = count +1; count = count +1; While (count <= n){ } count = 1; int sum; int count; int n; sum = 0; scanf(“%d”,&n);


Download ppt "Introduction to Problem SolvingS1.2.1 Bina © 1998 Liran & Ofir Introduction to Problem Solving Programming in C."

Similar presentations


Ads by Google