Documente Academic
Documente Profesional
Documente Cultură
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:
Purpose of computers
Informal definition
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
8.6
Defining actions
History of algorithm
Algorithm name came from Arab Mathematician Abu Jafar Mohammed ibn Musa al-khowarizmi al-khowarizmi was called algorithm.
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.
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
Flowchart
Definition: Pictorial representation of an algorithm. shows logic of an algorithm emphasizes individual steps and their interconnections
Flow of control
19
START
Input M1,M2,M3,M4
GRADE(M1+M2+M3+M4)/4
IS GRADE<50
PRINT PASS
PRINT FAIL
STOP
20
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); } }
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
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:
x1 = (b + d)/2a and
START
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
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
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.