[go: up one dir, main page]

67% found this document useful (3 votes)
1K views10 pages

Cse 20cs11t U5 Notes

The document provides information on computer programs, algorithms, and flowcharts. It defines a program as a sequence of instructions given to a computer to perform a specified task. An algorithm is defined as a finite sequence of instructions that produces an output when given input. The document includes examples of algorithms for addition, subtraction, and finding the largest/smallest of three numbers. It describes how flowcharts provide a pictorial representation of algorithms using different shapes and arrows. The document also discusses different generations of programming languages from machine language to high-level languages.

Uploaded by

Vikas E159 CS21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
67% found this document useful (3 votes)
1K views10 pages

Cse 20cs11t U5 Notes

The document provides information on computer programs, algorithms, and flowcharts. It defines a program as a sequence of instructions given to a computer to perform a specified task. An algorithm is defined as a finite sequence of instructions that produces an output when given input. The document includes examples of algorithms for addition, subtraction, and finding the largest/smallest of three numbers. It describes how flowcharts provide a pictorial representation of algorithms using different shapes and arrows. The document also discusses different generations of programming languages from machine language to high-level languages.

Uploaded by

Vikas E159 CS21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Fundamentals of Computer 20CS11T 2020-21

UNIT V: INTRODUCTION TO COMPUTER


• PROGRAM
➢ A Program consists of a sequence of instructions that is given to a
computer .
➢ The collection of instructions forms a program.
OR
➢ A computer program is a sequence of instructions written using a
Computer Programming Language to perform a specified task by the
computer.
➢ A program is used as a synonym for software.

• ALGORITHM
• An algorithm is defined as a finite sequence of instructions that when
provided with a set of input values produces an output and then
terminates.
• To be an algorithm, the steps must be unambiguous and after a finite number
of steps, the solution of the problem should be achieved.
• However, algorithms can have steps that repeat (iterate) or require decisions
(logic and comparison) until the task is completed.
• The need of an algorithm can be understood as it provides a logical
structure to plan the solution.
1. Algorithm for adding two numbers
Step 1: Start
Step 2: Declare variables num1, num2 and sum.
Step 3: Read values for num1, num2.
Step 4: Add num1 and num2 and assign the result to a variable sum.
Step 5: Display sum
Step 6: Stop

2. Algorithm for subtracting two numbers


Step 1: Start

Step 2: Read two numbers A and B

Step 3: Answer = A - B

Step 4: Display Answer

Step 5: Stop

3. Algorithm: To determine largest of three numbers

1. Start
2. Read three numbers A, B, C
3. Find the larger number between A and B and store it in MAX_AB

Computer Science & Engineering Page 1


Fundamentals of Computer 20CS11T 2020-21

4. Find the larger number between MAX_AB and C and store it in MAX
5. Display MAX=4
6. Stop

4. Algorithm: To determine smallest of three numbers

1. Start
2. Read three numbers A=1, B=3, C=5
3. Find the smaller number between A and B and store it in MIN_AB=1
4. Find the smaller number between MIN _AB=1 and C=5 and store it in MIN=1
5. Display MIN=1
6. Stop

5. Algorithm : Calculate and print sum of 'N' numbers

Step 1 : Start
Step 2 : Read how many numbers are to be considered for sum i.e addition &
store it in variable N
Step3 : Initialize the variable sum=0 & count=0
Step 4: Read the first number & store it in A
Step 5: Compute sum=sum+A
Step 6 :Compute count=count+1
Step 7: Check whether the value of COUNT is less than n i.e “count<N”, if
yes repeat the steps 4,5,6 other go to next step i,e 8
Step 8 : Print sum
Step 9 : Stop

FLOWCHART
• A flowchart is a pictorial representation of an algorithm.

• Here each steps are drawn in the form of different shapes of boxes and the
logical flow is indicated by arrows or flow lines.
• The boxes represent operations and the arrows represent the sequences
• The use of the flowchart is to help the programmer understand the logic of the
program.

Importance of Flowcharts
• A flowchart helps to check how to work on problem and how they could be
improved.
• It help to draw clear lines between where one process ends and the next one
starts.

Computer Science & Engineering Page 2


Fundamentals of Computer 20CS11T 2020-21

• Flowchart Symbols

• Flowchart Structures

• Sequence, where information can flow in a straight line or one by one.


• Selection (branched), where the decisions are made according to some
predefined condition.
• Repetition, where the logic repeat in a loop, that is, where a sequence of steps
is repeated until the desired output is obtained.

• Sequence
• As the name implies, in a sequence structure, the instructions are computed one
by one.

Example :Addition of two numbers:

Computer Science & Engineering Page 3


Fundamentals of Computer 20CS11T 2020-21

• Selection
• A selection structure allows the program to make a choice between two alternate
paths, depending upon the condition, whether it is true or false.
The flowchart, finds out the maximum / LARGEST of three numbers.

• Repetition
• Repetition or loop pattern causes an interruption in the normal sequence of
processing and directs the system to loop back to a previous statement in the
program, repeating the same sequence over and again, usually with new data.
Example: The flowchart, finds out the average of N numbers.

Computer Science & Engineering Page 4


Fundamentals of Computer 20CS11T 2020-21

• here are two forms of decision making constructs


• IF- THEN construct
• IF- ELSE construct
• IF-THEN construct: IF – THEN is the most basic of decision making.
The flowchart of IF-THEN construct can be expressed as:

Computer Science & Engineering Page 5


Fundamentals of Computer 20CS11T 2020-21

1. Algorithm to find the sum of first ‘n’ natural numbers


Step 1: Start
Step 2 : Initialize sum=0
Step 3: Read the value of n
Step 4: IF (n > 0) THEN
sum= sum+n
n=n-1
ENDIF
Step 5: print sum
Step 6: Stop

Generations of Languages
There are five generation of Programming languages. They are:
First Generation Language: Machine language
▪ These are low-level languages like machine language.
▪ Computers are electronic devices which can understand only binary codes.
▪ These binary codes are 0s and 1s also called as machine codes.
▪ Machine language is the only language a computer is able to understand.
▪ Language translators are not used here.
▪ This language is machine dependent.
▪ They are difficult to remember and understand for human beings

Computer Science & Engineering Page 6


Fundamentals of Computer 20CS11T 2020-21

Ex: 00000011001
Advantages of machine language:
• Translation free: They are translation free and can be directly executed by the
computers. Because computer can easily understand.
• High Speed: The programs written in these languages are executed very fast
as no translation is required.
• Efficient memory usage: The programs written in these languages utilize the
memory in an efficient manner.
Disadvantages of machine language:
• Machine dependent: A program developed in one computer cannot be run in
another computer. So it is very costly.
• Complex Or difficult language: It is difficult to read and write this
language.
• Error prone: Since programmer has to remember all instructions in binary
code, more chances of making errors.
Second Generation Languages [2GL]: Assembly language
▪ These assembly languages allows user to interact directly with hardware.
▪ These use mnemonic codes.
▪ Better readable than binary or machine language.
▪ Assembly language is also low-level programming language for a computer
▪ These are machine dependent languages.
▪ Translators called assemblers are used here.
▪ Assemblers are translators used to translate Assembly language into machine
language Ex: NASM, MASM, etc.
▪ It looks like MOV A ,B

Advantages of Assembly language


• Easy to understand and use: Assembly language uses mnemonics instead
of binary codes. Hence programs written in assembly language are easier
than machine language.
• Less error prone: Since mnemonics are used, programmer can keep track
of instructions storage.

Computer Science & Engineering Page 7


Fundamentals of Computer 20CS11T 2020-21

• Control on hardware: Assembly language gives direct access to hardware


.So it is easy to control the machine.
Disadvantages of Assembly language
• Machine dependent: Different computers have their own architecture and
assembly language.So they are not portable.
• Harder to learn: Being a machine dependent language,programmers have
to learn different assembly programs for different computers.
• Less efficient: IT is less efficient compared to machine language.

• No support for modern technology.


Third Generation Languages : High level language
▪ These are high level languages similar to English language.
▪ High level languages are human readable and easy to understand.
▪ A high-level language is designed to simplify computer programming.
▪ High-level source code contains easy-to-read syntax
▪ But machines cannot understand high level language.
▪ It requires a translator to convert into a machine-level language
▪ Translators called compilers and interpreters are used.
▪ Example for high-level languages are C, C++, Java, Visual Basic and
JavaScript.

Advantages of high-level language


• Easy to develop and understand: It is easy to develop, learn and understand
the program.
• Less error prone: As the program written in these languages are less prone to
errors, they are easy to maintain.
• Machine independent: Programs written in high level language can be used
in other computers also with very little or no change. They are portable.
• Easy to maintain: Programs are easily upgradable.
• Easy debugging: Programmers can easily debug using compilers and
interpreters

Computer Science & Engineering Page 8


Fundamentals of Computer 20CS11T 2020-21

• Less development cost: The program written in these languages can be


developed in very less time and cost as compared to the first- and second-
generation language.
Disadvantages of high-level language:
• Requires language translator
• Poor control on hardware:
Fourth Generation Languages:
▪ They bring advancement in third-generation programming languages (3GL).
▪ Languages in 4GL support for database management, GUI development, or
web development.
▪ These are languages similar to statements in the human language.
▪ These languages are more programmer-friendly, powerful.
▪ These are used mainly in database programming and scripting. Example of
these languages include Perl, Python, Ruby, SQL, MatLab.
Advantages of fourth generation languages
• allow the efficient use of data by using database.
• They require less time, cost and effort to develop software applications.
• These language programs are highly portable as compared other
programming languages.
Fifth Generation Languages:
▪ Based on problem-solving given to the computer, rather than using an
algorithm written by a programmer.
▪ logic-based programming languages are fifth-generation languages.
▪ fifth-generation languages are designed to make the computer solve a given
problem without the programmer.
▪ This way, the user only needs to worry about what problems need to be
solved and what conditions need to be met, without worrying about how to
implement a routine or algorithm to solve them.
▪ Fifth-generation languages are used mainly in artificial intelligence research.
▪ These have visual tools to develop a program. Examples of fifth generation
language include Mercury, OPS5, and Prolog.
Advantages of fifth generation languages
• These languages can be used to query the database in a fast and efficient
manner.

Computer Science & Engineering Page 9


Fundamentals of Computer 20CS11T 2020-21

• In this generation of language, the user can communicate with the computer
system in a simple and an easy manner.
Variables

Variables are the names given to computer memory locations.

They are used to store values in a computer program.
Examples of valid variable names:
age, gender, x25, reg_num, _book.

There are some rules for naming a variable


• The name of a variable can be composed of letters, digits, and the underscore
character.
• It must begin with either a letter or an underscore.
• Upper and lowercase letters are distinct.
• A variable name can hold a single type of value.
• Use only a....z, A....Z, 0....9 in your variable names and start their names using
alphabets only instead of digits.
• Almost none of the programming languages allow to start their variable names
with a digit.
Constants
Constants refer to fixed values that the program may not alter during its execution.
These fixed values are also called literals
Integer Literals
An integer literal can be a decimal, octal, or hexadecimal constant. Here are some
examples of integer literals −
212

Floating-point Literals
A floating-point literal has an integer part, a decimal point, a fractional part, and an
exponent part. Example:3.14159
Character Constants
Character literals are enclosed in single quotes, e.g., 'x' can be stored in a simple
variable of char type.
String Literals
String literals or constants are enclosed in double quotes " ".
“Hello”.

Computer Science & Engineering Page 10

You might also like