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

lesson 2

الكلية كلية العلوم للبنات     القسم قسم الحاسبات     المرحلة 1
أستاذ المادة ماجد جبار جواد الفنهراوي       10/11/2018 05:42:29
1. Algorithm:
To write a logical step-by-step method to solve the problem is called algorithm, in other words, an algorithm is a procedure for solving problems. In order to solve a mathematical or computer problem, this is the first step of the procedure. An algorithm includes calculations, reasoning and data processing. Algorithms can be presented by natural languages, pseudo code, etc.
In programming, algorithm are the set of well-defined instruction in sequence to solve a program. An algorithm should always have a clear stopping point.
Algorithm properties:
1. Inputs and outputs should be defined precisely.
2. Each steps in algorithm should be clear and unambiguous.
3. Algorithm should be most effective among many different ways to solve a problem.
4. An algorithm shouldn t have computer code. Instead, the algorithm should be written in such a way that, it can be used in similar programming languages.
Examples of Algorithms in Programming
Example 1:
Write an algorithm to add two numbers entered by user.
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum?num1+num2
Step 5: Display sum
Step 6: Stop

Example 2:
Write an algorithm to find the largest among three different numbers entered by user.
Step 1: Start
Step 2: Declare variables a,b and c.
Step 3: Read variables a,b and c.
Step 4: If a>b
If a>c
Display a is the largest number.
Else
Display c is the largest number.
Else
If b>c
Display b is the largest number.
Else
Display c is the greatest number.
Step 5: Stop
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 purpose of a flowchart is to analyze different processes.
Example 1:
Algorithm: Print numbers from 1 to 20:
Step 1: Start
Step 2: Initialize X as 0
Step 3: Increment X by 1
Step 4: Print X
Step 5: If X is less than 20 then go back to step 3
Step 6: Stop

Example 2:
Algorithm: Convert Temperature from Fahrenheit (?) to Celsius (?)
Step 1: Start
Step 2: Read temperature in Fahrenheit
Step 2: Calculate temperature with formula C=5/9*(F-32)
Step 3: Print C
Step 4: Stop


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