Sunteți pe pagina 1din 30

Introduction to Computing Technologies-ICT

Name of Book: Author: Subject code: Credits: Fundamentals of computers. V.Rajaraman 13CT101 4

Trupti V.G

Chapter 1
Idea of an algorithm

Learning Objectives:

Parts of computer Characteristics of computers

Purpose of computers

Informal definition

An informal definition of an algorithm is:

Algorithm: a step-by-step method for solving a problem or doing a task.

Informal definition of an algorithm used in a computer

8.3

Example
Preparing Maggi

Ingredients: water 2 cups, maggi noodles 1 pack. Method: Step 1: Boil 2 cups of water Step 2: Add maggi noodles to it Step 3: Add maggi masala to the noodles Step 4: Cook for 5 minutes till the noodles bake well Result: Maggi noodle ready to eat

Algorithm

Example: Finding the largest integer among five integers

8.6

Defining actions

Writing algorithm for the example

History of algorithm
Algorithm name came from Arab Mathematician Abu Jafar Mohammed ibn Musa al-khowarizmi al-khowarizmi was called algorithm.

Characteristics of algorithm Finite sequence of instructions. Characteristics:


Begins with inputs, inputs are instructions. Processing rules specified in the algorithm must be precise and unambiguous. Basic instructions that can be understood and carried out. Time taken to carry out all the steps in algorithm must be finite. It must produce one or more outputs.

Algorithm to find no of vowels in a paragraph


Step 1: let number of characters =0
Step 2: let number of vowels=0 Step 3: repeat steps 4,5,6,7 till end of paragraph Step 4: read one character from passage Step 5: add 1 to number of characters Step 6: if the character is any one of the letters A,E,I,O,U,a,e,I,o,u, add 1 to number of vowels Step 7: Move to next character Step 8: average no of vowels=number of vowels/ number of characters

Step 9: write avg no of vowels, number of characters


Step 10: stop

Write an algorithm to convert the length in feet to centimeter.

Algorithm Step 1: Input the length in feet Step 2: Calculate the length in cm by multiplying LFT with 30 Step 3: Print length in cm

What is a computer?
An electronic machine that can be programmed to accept data (input), and process it into useful information (output). Computers are devices powered by electricity, which has two discrete states: On or Off.

A simple model of a computer

Input unit

Memory

Output

Processing unit

14

Configuration
Input unit:
Read the algorithm and data to be processed.

Memory unit:
Stores the algorithm and computes the values.

Processing unit:
Interprets the instruction and carries arithmetic operations, character manipulation operations and logical operations.

Output unit:
Prints or displays result.

Characteristics of a computer
Processes various instructions. Simple instructions High speed Precise No mistakes

Problem solving using computers


Steps: Given problem is analyzed. Methods broken into sequence of tasks. Algorithm is expressed in a precise notation (computer programming language) Computer program is fed into the computer Processing is done and results are sent to output unit

Flowchart
Definition: Pictorial representation of an algorithm. shows logic of an algorithm emphasizes individual steps and their interconnections

Ex: find the total marks and calculate grade.

Rectangles with rounded ends Start / stop


Parallelograms Input / output

Flow of control

Rectangles to show Processing steps

Diamond shape box For Decision making

19

START

Input M1,M2,M3,M4

GRADE(M1+M2+M3+M4)/4

IS GRADE<50

PRINT PASS

PRINT FAIL

STOP
20

Draw a flowchart to convert the length in feet to centimeter.


START

Input Length in feet

Length in cm Lft x 30

Print Length in cm

STOP

A Program
Programming Language: expressing flowchart in a more precise and concise notation. Examples: Java programming language, c, FORTRAN
Class a { public static void main(String[] args) // an example of java program { int m1=10, m2=20, m3=40, m4=35; int avg; avg=(m1+m2+m3+m4)/4; System.out.println(avg); } }

Stored program concept


Model of a computer: Proposed by John Von Neumann in 1945. Concept: Storing a program and processing the data in the same memory Use: Repetitive execution of series of instructions. Storing a program in memory makes the operations automatic without human intervention.

Write an algorithm and draw a flowchart that will read the two sides of a rectangle and calculate its area Algorithm Step 1: Step 2: Step 3:
START

Input W,L AL x W Print A

Input W, L

Pseudocode Input the width (W) and Length (L) of a rectangle Calculate the area (A) by multiplying L with W Print A

ALxW

Print A

STOP

Write an algorithm and draw a flowchart that will calculate the roots of a quadratic equation ax2+bx+c=0 Hint: d = sqrt (b2 x2 = (b d)/2a Algorithm: Step 1: Step 2: Step 3: Step 4: Step 5:

4ac), and the roots are:

x1 = (b + d)/2a and
START

Input a, b, c d sqrt ( b b 4 a c x1 (b + d) / (2 x a) x2 (b d) / (2 x a) Print x1, x2

Input a, b, c

)
d sqrt(b x b 4 x a x c) x1 (b + d) / (2 x a) X2 (b d) / (2 x a) Print x1 ,x2

STOP

Given 3 assignment marks (out of 50, 20, 70), find the average (calculated as a mark out of 100)

General Concept
How does one figure out the percentage of several marks?
Add them all up Divide by the maximum possible mark (50+20+70) Multiply by 100

Given 3 assignment marks (out of 50, 20, 70), find the average, calculated as a mark out of 100
Algorithm: Set MaxMark = 140 (Constant) Step 1: Get A1 Step 2: Get A2 Step 3: Get A3

Step 4 Let Total = A1 + A2 + A3 Step 5: Let Mark = Total/MaxMark * 100


Step 6: display result

Given a two digit number, find the sum of its digits General Concept
How can we break apart a number?
41 = 4 Tens and 1 Ones so for the number 41, we want 4 + 1 = 5

41 / 10 = 4

Use integer division


DIV returns the integer part of a division MOD returns the remainder of a division
41 MOD 10 = 1

Given a two digit number, find the sum of its digits


ALGORITHM: Step 1: Get N Step 2: Let Tens = N div 10 Step 3: Let Ones = N mod 10 Step 4: Let Sum = Tens + Ones Step 5: Display Sum

Exercise problems
Write an algorithm and flowchart to add two numbers and check if the resulting number is even or odd. Write an algorithm to find the direction or path from PESIT to chinnaswamy stadium.

S-ar putea să vă placă și