انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

LESSON TWO

الكلية كلية العلوم للبنات     القسم قسم الحاسبات     المرحلة 1
أستاذ المادة هديل قاسم غني       27/12/2016 21:34:40
1. Algorithm:
As stated earlier an algorithm can be defined as a finite sequence of
effect statements to solve a problem. An effective statement is a clear,
unambiguous instruction that can be carried out .Thus an algorithm should
special the action to be executed and the order in which these actions are to
be executed.
Algorithm properties:
? Finiteness: the algorithm must terminate a finite number of steps.
? Non-ambiguity: each step must be precisely defined. At the
completion of each step, the nest step should be uniquely determined.
? Effectiveness: the algorithm should solve the problem in a reasonable
amount of time.
Example 1: Develop an algorithm that inputs a series of number and output
their average .
A computer algorithm can only carry out simple instruction like:
? "Read a number".
? "Add a number to anther number".
? "Output a number".
Thus an algorithm is:
1. Carry out initialization required.
2. Read first number.
3. While the number of numbers is not complete do
4. begin
5. Add the number to the accumulated sum.
6. increment the count of numbers entered.
LECTURE 2
LESSON TWO
7. Read next number.
8. End
9. Evaluate the average.
Example 2: Devolve an algorithm that allows the user to enter the count of
numbers in a list followed by these numbers. The algorithm should find and
output the minimum and the maximum numbers in the list.
An algorithm for this might be:
? Initialize.
? Get count of numbers.
? Enter numbers and find maximum and minimum .
? Output result.
The user might enter zero for the count. To deal with this case the above
general case can be extended as follows to be an algorithm:
1. Initialize the require variables.
2. Get count of numbers.
3. If count is zero then exit.
4. Otherwise begin.
5. Enter numbers.
6. Find max and min.
7. Output result.
8. End.
2. Flowcharts
A flowchart is a graphical representation of an algorithm or of a portion
of an algorithm .Flowcharts are drawn using symbols. The main symbols used
to draw a flowchart are shown in following figure.
LESSON TWO
Start and Stop Symbols
Input and Output Symbols
Mathematical and logical
processing symbol
Decision making symbol
Connector symbols
Start
Stop
Read Print
X=Y * Z
Condition
1A
2A
LESSON TWO
Example 1:
Draw a flowchart to read 3 numbers: x , y and z and print the largest
number of them.
Max=z
Start
Read x
Read y
Read z
Print max
Max=x
Max=y
y>max
?
z>max
?
End
No
Yes
No
Yes
LESSON TWO
Example 2:
Draw the flowchart required to find the sum of negative numbers
among 50 numbers entered by the user.
Start
End
Read number
Print sum
Is
number<
0
Is
counter
> 50
Counter=0
Sum=0
Counter=counter+1
Sum=sum + number
NO
Yes
NO
Yes
LESSON TWO

المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .