Sunteți pe pagina 1din 22

GE6151 Computer Programming Short Notes Unit 1

Question 1 Give an introduction (or) evolution to Computer in details


Point 1: A Computer is an electronic machine that takes input from the user, processes the
given input and generates output in the form of useful information.
Point2: Note: include application, components and characteristics of computer if necessary
Point 3: Evolution of Computer:
1. Manual Computing devices
a. Sand table (First Computing Device)
i. Used stones for representing numbers
ii. Stones were arranged in 3 channels
iii. Each channel could have maximum 10 stones
b. Abacus (5000 Years back)
i. Used beads, wires and wooden frames
ii. Calculations are performed by sliding beads
iii. Still used around the world
c. Napier Bones (1614)
i. Developed by John Napier
ii. Used for multiplication of 2 numbers
iii. Used bones for calculation
2. Automatic Computing Machine
a. Difference Engine (1822)
i. Developed by Charles Babbage
ii. Was the first automatic computing device
iii. Was capable of solving numerical problems
b. MARK 1 (1944)
i. Developed by Howard Aiken
ii. Was capable of multiplying 20 figures in 6 sec.
iii. Was large and noisy
c. ENIAC (1946)
i. Developed by John Eckert and John Mauchly
ii. Used vacuum tubes
iii. Was 1000 times faster than MARK 1
d. UNIVAC (1951)
i. Developed by Ecker-Mauchly computer corporation
ii. Was capable of processing alphabets & numbers
iii. Used 5200 vacuum tubes
3. Modern Computing Devices
We discuss it in Computer Generations
Question 2 Explain in detail about generation of Computer
In computing, various computing devices were invented that enabled people to solve different
types of problems, such computing devices are classified into several generations. The history of
computer development is often referred in terms of different generation of computer, as listed below
First Generation Computers
Second Generation Computers
Third Generation Computers
Fourth Generation Computers
Fifth Generation Computers
1. First Generation of Computers
a. Employed during the period 1940 1956
b. Used Vacuum tubes technology for calculation as well as for storage and control purposes
c. Punched cards and printout are used for input and output respectively
d. Examples are ENIAC, EDVAC, EDSAC, UNIVAC





2. Second Generation Computers
a. Employed during the period 1956 1963
b. Use of transistors in place of vacuum tubes in building the basic logic circuit
c. A transistor is a semiconductor device that is used to increase power of incoming signals
d. Punched cards and printout are used for input and output respectively
e. Examples are PDP-8, IBM 1401 and IBM 7090






3. Third generation computers
a. Employed during the period 1964 1975
b. Use of Integrated Circuits (ICs)
c. ICs are the circuits that combine various electronic components, such as transistors,
resistors, capacitors and etc., onto a single small silicon chip
d. Examples are NCR 395, B6500, IBM 370, PDP 11 and CDC 7600




4. Fourth generation computers
a. Employed during the period 1975 1989
b. Use of Microprocessors (i.e., bczs of development of LSI & VLSI)
Advantages: 1. fastest computing device of their time
2. able to execute complex mathematical problems
Disadvantage: 1. Depend on the machine language
2. Special purpose computer, also very large and bulky
Advantages: 1. uses the assembly language
2. Required very less power, and produces less heat
Disadvantage: 1. requires air-conditioned place
2. Cost of this computer is very high
Advantages: 1. uses the high level language
2. able to execute any type of application (General purpose)
Disadvantage: 1. Storage capacity is still very small
2. Cost of this computer is very high, still requires air-conditioned place
c. A microprocessor incorporates various components of a computer such as CPU, memory
and etc., onto a single chip
d. Examples are IBM PC, Apple, CRAY-1






5. Fifth generation Computers
a. After 90s until now all the modern digital computer comes under this category
b. Uses ULSI (Ultra Large Scale Integration)or SLSI(Super Large Scale Integration)
c. ULSI helps in increasing the power and speed of the microprocessor








Question 3 Explain in detail about Classification of Computer

Point 1: We can classify Computers according to the following three criteria:

Based on,
Operating Principle (or) Functionality
Size (or) Capacity
Applications (or) Purpose

Point2:
Based on Operating Principle (or) Functionality
It is further classified into
Analog Computer
Digital Computer
Hybrid Computer
Analog Computer
An analog computer is a form of computer that uses continuous physical phenomena such as
electrical, mechanical, or hydraulic quantities to model the problem being solved
Computers that measure changing conditions like temperature, pressure etc. and convert the
numerical into quantities within a range are called Analog Computer
Analog Computers are employed for specific scientific/ technological operations
Digital Computer
A computer that performs calculations and logical operations with quantities represented as
digits, usually in the binary number system
A digital computer can give precise and measurable results.
Advantages: 1. Increases the storage capacity, highly reliable
2. Requires very less power to operate
Disadvantage: 1. Soldering of LSI and VLSI is tough
2. Still depends on programmer instruction
Advantages: 1. Fastest and powerful computers till date
2. Highly reliable for communication
Disadvantage: 1. No artificial intelligence
2. lack of human like intelligence
The digital computers applications are universal, i.e., from science to business to
administration and others.
For that reasons, these are very popular now-a-days.
Hybrid Computer (Analog + Digital)
A combination of computers those are capable of inputting and outputting in both digital and
analog signals. A hybrid computer system setup offers a cost effective method of performing
complex simulations.
Microcomputers are called Hybrid Computers, which have digital storage and switching but
calculations are done in an analog fashion.
Point3:
Based on Size or Capacity
It is further classified into
Micro-computers
Mini-computers\
Mainframes
Super computers
1. Micro computers
A micro computer contains Micro processor, a CPU on a single silicon chip i.e., 8088, 8086
etc. It has limited internal memory and is relatively slow.
Its rate of acceptance and transfer of data is a maximum of 5 lake bytes/second.
It is small, portable, inexpensive occupies less space and consumes very less power.
Personal Computers (PC) are the best example of this kind.
Desktop Computer: a personal or micro-mini computer sufficient to fit on a desk.
Laptop Computer: a portable computer complete with an integrated screen and keyboard. It is
generally smaller in size than a desktop computer and larger than a notebook computer.
Palmtop Computer/Digital Diary /Notebook /PDAs: a hand-sized computer. Palmtops have
no keyboard but the screen serves both as an input and output device.

2. Mini computers
A mini computer is bigger than a micro-computer and smaller than a mainframe.
It has a medium speed processor; more internal memory capacity compared to micros and
can support all high level languages.
It can perform most tasks that a mainframe can do.
In general, a minicomputer is a multiprocessing system capable of supporting from 4 to about
200 users simultaneously.

3. Mainframes
These are huge machines with high speed configured with host processor and subordinate
processors.
They have large internal storage capacity i.e., about 10 mega words and support greater than
200 remote terminals.
They are able to accept any high level language. But their main drawbacks are, very high
cost, requirement of large space, very high electricity consumption, and high cost of
maintenance.
Their main uses are at government offices and research institutions.


4. Super computers
Supercomputers are more powerful than mainframes and can process several hundreds or
even thousands million instructions per second.
They are designed for high precision based application and have vast processing power
applied in a narrow range.
They are mostly used in research centers, complicated military and scientific jobs such as
weather forecasting, cracking of enemy codes, predicting how a nuclear bomb will explode
and designing missiles and jet fighters.

Point4:
Based on Application or Purpose
It is further classified into
General purpose
Specific purpose
1. General Purpose
General purpose computers are designed to perform a range of tasks.
They have the ability to store numerous programs, but lack in speed and efficiency.
2. Special Purpose

Specific purpose computers are designed to handle a specific problem or to perform
a specific task.
A set of instructions is built into the machine.



Question 4 Explain in detail about Basic Computer Organization

A computer can process data, pictures, sound and graphics. They can solve highly complicated
problems quickly and accurately.


Input Unit:
Computers need to receive data and instruction in order to solve any problem. Therefore we
need to input the data and instructions into the computers.
The input unit consists of one or more input devices. Keyboard is the one of the most
commonly used input device.
Other commonly used input devices are the mouse, floppy disk drive, magnetic tape, etc.
All the input devices perform the following functions.
o Accept the data and instructions from the outside world.
o Convert it to a form that the computer can understand.
o Supply the converted data to the computer system for further processing.

Storage Unit:
The storage unit of the computer holds data and instructions that are entered through the
input unit, before they are processed.
It preserves the intermediate and final results before these are sent to the output devices. It
also saves the data for the later use.
Types of Storage Devices:
1. Primary Storage:
1. Stores and provides very fast.
2. This memory is generally used to hold the program being currently executed in the
computer, the data being received from the input unit, the intermediate and final results of
the program.
3. The primary memory is temporary in nature. The data is lost, when the computer is
switched off.
4. In order to store the data permanently, the data has to be transferred to the secondary
memory. The cost of the primary storage is more compared to the secondary storage.
2. Secondary Storage:
1. It stores several programs, documents, data bases etc.
2. The programs that run on the computer are first transferred to the primary memory
before it is actually run.
3. Whenever the results are saved, again they get stored in the secondary memory.
4. The secondary memory is slower and cheaper than the primary memory. Some of the
commonly used secondary memory devices are Hard disk, CD, etc.,

Memory Size:
All digital computers use the binary system, i.e. 0s and 1s.
Each character or a number is represented by an 8 bit code.
The set of 8 bits is called a byte. A Character occupies 1 byte space.
A numeric occupies 2 byte space. Byte is the space occupied in the memory.
The size of the primary storage is specified in KB (Kilobytes) or MB (Megabyte).
One KB is equal to 1024 bytes and one MB is equal to 1000KB.
The size of the primary storage in a typical PC usually starts at 16MB. PCs having 32 MB,
48MB, 128 MB, 256MB memory are quite common.

Output Unit:
The output unit of a computer provides the information and results of a computation to
outside world. Printers, Visual Display Unit (VDU) are the commonly used output devices.
Other commonly used output devices are floppy disk drive, hard disk drive, and magnetic
tape drive.

Central Processing Unit:
The control unit and ALU of the computer are together known as the Central Processing Unit
(CPU).
The CPU is like brain performs the following functions:
o It performs all calculations.
o It takes all decisions.
o It controls all units of the computer.
A PC may have CPU-IC such as Intel 8088, 80286, 80386, 80486, Celeron, Pentium,
Pentium Pro, Pentium II, Pentium III, Pentium IV, Dual Core, and AMD etc.

Arithmetic Logical Unit:
o All calculations are performed in the Arithmetic Logic Unit (ALU) of the computer. It also
does comparison and takes decision.
o The ALU can perform basic operations such as addition, subtraction, multiplication, division,
etc and does logic operations viz, >, <, =, etc.
o Whenever calculations are required, the control unit transfers the data from storage unit to
ALU once the computations are done, the results are transferred to the storage unit by the
control unit and then it is send to the output unit for displaying results.


Control Unit:
o It controls all other units in the computer. The control unit instructs the input unit, where to
store the data after receiving it from the user.
o It controls the flow of data and instructions from the storage unit to ALU. It also controls the
flow of results from the ALU to the storage unit.
o The control unit is generally referred as the central nervous system of the computer that
control and synchronizes its working.



Question 5 Explain Number System in Details

When we type some letters or words, the computer translates them in numbers as computers can
understand only numbers.
A computer can understand positional number system where there are only a few symbols called
digits and these symbols represent different values depending on the position they occupy in the
number.

A value of each digit in a number can be determined using

The digit
The position of the digit in the number
The base of the number system (where base is defined as the total number of digits
available in the number system).


Decimal Number System

The number system that we use in our day-to-day life is the decimal number system.
Decimal number system has base 10 as it uses 10 digits from 0 to 9. In decimal number system,
the successive positions to the left of the decimal point represent units, tens, hundreds, thousands
and so on.
Each position represents a specific power of the base (10). For example, the decimal
number 1234 consists of the digit 4 in the units position, 3 in the tens position, 2 in the hundreds
position, and 1 in the thousands position, and its value can be written as

(1x1000)+ (2x100)+ (3x10)+ (4xl)
(1x10
3
)+ (2x10
2
)+ (3x10
1
)+ (4xl0
0
)
1000 + 200 + 30 + 4
1234

As a computer programmer or an IT professional, you should understand the following number
systems which are frequently used in computers.

S.N. Number System & Description
1
Binary Number System
Base 2. Digits used: 0, 1
2
Octal Number System
Base 8. Digits used: 0 to 7
4
Hexa Decimal Number System
Base 16. Digits used: 0 to 9, Letters used: A- F

Binary Number System

Characteristics
Uses two digits, 0 and 1.
Also called base 2 number system
Each position in a binary number represents a 0 power of the base (2). Example 2
0

Last position in a binary number represents a x power of the base (2). Example 2
x
where
x represents the last position - 1.

Example
Binary Number: 10101
2
Calculating Decimal Equivalent:
Step Binary Number Decimal Number
Step 1 10101
2
((1 x 2
4
) + (0 x 2
3
) + (1 x 2
2
) + (0 x 2
1
) + (1 x 2
0
))
10

Step 2 10101
2
(16 + 0 + 4 + 0 + 1)
10

Step 3 10101
2
21
10

Note: 10101
2
is normally written as 10101.
Octal Number System

Characteristics
Uses eight digits, 0,1,2,3,4,5,6,7.
Also called base 8 number system
Each position in a octal number represents a 0 power of the base (8). Example 8
0

Last position in a octal number represents a x power of the base (8). Example 8
x
where x
represents the last position - 1.

Example
Octal Number: 12570
8

Calculating Decimal Equivalent:
Step Octal Number Decimal Number
Step 1 12570
8
((1 x 8
4
) + (2 x 8
3
) + (5 x 8
2
) + (7 x 8
1
) + (0 x 8
0
))
10

Step 2 12570
8
(4096 + 1024 + 320 + 56 + 0)
10

Step 3 12570
8
5496
10

Note: 12570
8
is normally written as 12570.

Hexadecimal Number System

Characteristics
Uses 10 digits and 6 letters, 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F.
Letters represents numbers starting from 10. A = 10. B = 11, C = 12, D = 13, E = 14, F =
15.
Also called base 16 number system
Each position in a hexadecimal number represents a 0 power of the base (16). Example
16
0

Last position in a hexadecimal number represents a x power of the base (16). Example
16
x
where x represents the last position - 1.

Example
Hexadecimal Number: 19FDE
16

Calculating Decimal Equivalent:
Step Binary Number Decimal Number
Step 1 19FDE
16
((1 x 16
4
) + (9 x 16
3
) + (F x 16
2
) + (D x 16
1
) + (E x 16
0
))
10

Step 2 19FDE
16
((1 x 16
4
) + (9 x 16
3
) + (15 x 16
2
) + (13 x 16
1
) + (14 x 16
0
))
10

Step 3 19FDE
16
(65536+ 36864 + 3840 + 208 + 14)
10

Step 4 19FDE
16
106462
10

Note: 19FDE
16
is normally written as 19FDE.

Question 6 Number System Conversion Problems

There are many methods or techniques which can be used to convert numbers from one base to
another. We'll demonstrate here the following
Decimal to Non Decimal
o Decimal to Binary
o Decimal to Octal
o Decimal to Hexadecimal
Non Decimal to Decimal
o Binary to Decimal
o Octal to Decimal
o Hexadecimal to Decimal
Non Decimal to Non Decimal
o Binary to Octal
o Binary to Hexadecimal
o Octal to Binary
o Octal to Hexadecimal
o Hexadecimal to Binary
o Hexadecimal to Octal

Decimal to Non Decimal Base System

Steps
Step 1 - Divide the decimal number to be converted by the value of the new base.
Step 2 - Get the remainder from Step 1 as the rightmost digit (least significant digit) of
new base number.
Step 3 - Divide the quotient of the previous divide by the new base.
Step 4 - Record the remainder from Step 3 as the next digit (to the left) of the new base
number.
Repeat Steps 3 and 4, getting remainders from right to left, until the quotient becomes zero in
Step 3.The last remainder thus obtained will be the most significant digit (MSD) of the new base
number.
Example
Decimal Number: 29
10
Calculating Binary Equivalent:
Step Operation Result Remainder
Step 1 29 / 2 14 1
Step 2 14 / 2 7 0
Step 3 7 / 2 3 1
Step 4 3 / 2 1 1
Step 5 1 / 2 0 1
As mentioned in Steps 2 and 4, the remainders have to be arranged in the reverse order so that
the first remainder becomes the least significant digit (LSD) and the last remainder becomes the
most significant digit (MSD).
Decimal Number: 29
10
= Binary Number: 11101
2
.

Integer Part:
Use Division
Method
Fraction Part:
Use Carry Method
For Both Integer Part
& Fraction Part:
Use Multiplication Method
Note:
Use Only
Non-Decimal
Base

Here first convert the given Non Decimal to Decimal
and Convert the resulted Decimal to Non Decimal
i.e., Non Decimal to Non Decimal = Non Decimal to
Decimal to Non Decimal
Non Decimal to Decimal System
Steps
Step 1 - Determine the column (positional) value of each digit (this depends on the
position of the digit and the base of the number system).
Step 2 - Multiply the obtained column values (in Step 1) by the digits in the
corresponding columns.
Step 3 - Sum the products calculated in Step 2. The total is the equivalent value in
decimal.
Example
Binary Number: 11101
2
Calculating Decimal Equivalent:
Step Binary Number Decimal Number
Step 1 11101
2
((1 x 2
4
) + (1 x 2
3
) + (1 x 2
2
) + (0 x 2
1
) + (1 x 2
0
))
10

Step 2 11101
2
(16 + 8 + 4 + 0 + 1)
10

Step 3 11101
2
29
10

Binary Number: 11101
2
= Decimal Number: 29
10

Numeral systems conversion table
Decimal
Base-10
Binary
Base-2
Octal
Base-8
Hexadecimal
Base-16
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10
17 10001 21 11
18 10010 22 12
19 10011 23 13
20 10100 24 14
21 10101 25 15
22 10110 26 16
23 10111 27 17
24 11000 30 18
25 11001 31 19
26 11010 32 1A
27 11011 33 1B
28 11100 34 1C
29 11101 35 1D
30 11110 36 1E
31 11111 37 1F
32 100000 40 20

Conversion Problems: Non Decimal to Decimal

Example: Convert 10111
2
decimal number
10111
2
= 1 x 2
4
+ 0 x 2
3
+ 1 x 2
2
+ 1 x 2
1
+ 1 x 2
0

= 1 x 16 + 0 + 1 x 4 + 1 x 2 + 1 x 1
= 16 + 0 + 4 2 + 1
= 23
10

Example: Convert 101.101
2

101.101
2
= 1 x 2
2
+ 0x2
1
+ 1 x 2
0
+ 1x 2
-1
+ 0 x 2
-2
+ 1 x 2
-3

= 1 x 4 + 0 + 1 x 1 +1/2 + 0 + 1/8
= 4 + 0 + 1 + 0.5 + 0.125
= 5.625
10

Example: convert 45
8
to decimal number
45
8
= 4 x 8
1
+ 5 x 8
0

= 4 x 8 + 5 x 1
= 32 + 5
= 37
10

Example: Convert 3A
16
to decimal number
3A
16
= 3 x 16
1
+ A x 16
0

= 3 x 16 + 10 x 1
= 48 + 10
= 58
10

Conversion Problems: Decimal to Non Decimal







Question 7 Explain algorithm in detail
A set of step-by-step instructions to accomplish a task.
An algorithm must have start instruction
Each instruction must be precise.
Each instruction must be unambiguous.
Each instruction must be executed in finite time.
An algorithm must have stop instruction.
An algorithm is
o a step-by-step sequence of instructions
o to solve a specific problem
o in a finite amount of time.

Definition:
Algorithm is a finite set of instructions if followed accomplishes a particular task. (OR) a
step by step description of a particular task. An algorithm must satisfy the following
criteria.

Explanation
Input: an algorithm must take zero, one or more quantities as input
Output: must produce one or more outputs
Definiteness: each step of the algorithm must be clear and unambiguous.
Finiteness: an algorithm must terminate in finite number of steps.
Effectiveness: each step must be effective so that each step easily convertible into
program statement.

An algorithm is said to be accurate and truthful only when it provides the exact required
output. The steps in algorithm divided into three categories.
(1). Sequence
(2). Selection
(3). Iteration

(1). Sequence:
The steps described in an algorithm are performed successively one by one without
skipping any step.
Rules:
Each step is simple and easy to understand.
Each and every step in an algorithm is executed.

Example1: Adding of two numbers

step1: start
step2: read A, B
step3: C = A + B
step4: write C
step5: stop

In the above algorithm all the steps are successively executed one by one to perform addition of
A & B variables. You cannot skip any step in the above algorithm.

(2). Selection:
Depending on the condition you can skip the steps and directly select the desired step and
execute.

Example2: Maximum of two numbers

step1: start
step2: read A, B
step3: if(A>B)
step4: write A is Greater
step5: else write B is Greater
step6: stop

in the above algorithm depending on the condition in the step3, you can select either
step4 or step5

(3). Iteration:
Performing the some action number of times.

Example3: Print the numbers from 1 to 100

step1: start
step2: n =1
step3: write n
step4: n=n+1
step5: if(n<=100) goto step3
step6: stop

In the above case step3 & 4 are repeated until the condition in step5 fails.

Characteristics of Algorithm

In the Algorithms each and every instruction should be precise and unambiguous.
The instructions in an algorithm should not be repeated infinitely.
Ensure that the algorithm 1will ultimately terminate.
The algorithm should be written in sequence.
lt looks like normal English.
The desired result should be obtained only after the algorithm terminates.


Question 7 Explain Flowchart in detail
A flowchart is a diagrammatic representation that illustrates the sequence of operation to be
performed to arrive at a solution. The operating instructions are placed in boxes which are connected
by arrows to indicate the order of execution
A Flowchart is a graphical representation for an algorithm; it is the layout and visual representation
of the plan to be followed by the corresponding algorithm


Example: Flow chart for Example: Flow chart for
Adding two numbers Greatest of two numbers

Start
c = a + b
Read a, b
Write c
Stop
Start
Read a, b
Write a is
greater
Stop
Write b is
greater
If a>b
No Yes










General rules for flowcharts
All symbols of the flowchart are connected by flow lines (note arrows, not lines)
Flow lines enter the top of the symbol and exit out the bottom, except for the Decision
symbol, which can have flow lines exiting from the bottom or the sides
Flowcharts are drawn so flow generally goes from top to bottom
The beginning and the end of the flowchart is indicated using the Terminal symbol

Advantages of Using Flowcharts:
The benefits of flowcharts are as follows:
o Communication: Flowcharts are better way of communicating the logic of a
system to all concerned.
o Effective analysis: With the help of flowchart, problem can be analysed in more
effective way.
o Proper documentation: Program flowcharts serve as a good program
documentation, which is needed for various purposes.
o Efficient Coding: The flowcharts act as a guide or blueprint during the systems
analysis and program development phase.
o Proper Debugging: The flowchart helps in debugging process.
o Efficient Program Maintenance: The maintenance of operating program
becomes easy with the help of flowchart. It helps the programmer to put efforts
more efficiently on that part.

Limitations of Using Flowcharts:
Although a flowchart is a very useful tool, there are a few limitations in using flowcharts
which are listed below:
o Complex logic: Sometimes, the program logic is quite complicated. In that case,
flowchart becomes complex and clumsy.
o Alterations and Modifications: If alterations are required the flowchart may
require re-drawing completely.
o Reproduction: As the flowchart symbols cannot be typed, reproduction of
flowchart becomes a problem.
o The essentials of what is done can easily be lost in the technical details of how it
is done.

Question 7 Explain Pseudo-code (or pseudo code) in detail
Pseudo-code is writing an algorithm as close as possible to computing languages.
Pseudo-code is useful for describing algorithms in a structured way. It makes use of simple
English-like statements.
Consists of natural language-like statements that precisely describe the steps of an
algorithm or program
Statements describe actions
Focuses on the logic of the algorithm or program
Avoids language-specific elements
Written at a level so that the desired programming code can be generated almost
automatically from each statement
Steps are numbered. Subordinate numbers and/or indentation are used for dependent
statements in selection and repetition structures

Rules for writing pseudo code
1. Write one statement per line
2. Capitalize initial keyword
3. Indent to show hierarchy
4. End multiline structure
5. Keep statement languages independent

Advantages
1. It can be done easily in any word processor
2. It can be easily modified as compared to flowchart
3. It can be written easily and converting to program is easy

Disadvantages
1. It is not visual
2. We do not get a picture of the design
3. There is no standardized style or format
4. For beginners it is more difficult to follow the logic

Ex - 1: To calculate student total and average

Task List
Read name, class, marks. Calculate total and average. Write name, class, total, average.
Pseudo code
READ name, class, m1,m2,m3.
Total = m1+m2+m3
Average=TOTAL/3
WRITE name, class, total, average.
Ex 2: For a given value, Limit, what is the smallest positive integer Number for which the
sum Sum = 1 + 2 + ... + Number is greater than Limit. What is the value for this Sum?
Pseudo code: Input: An integer Limit
Ouput: Two integers: Number and Sum
1. Enter Limit
2. Set Number = 0.
3. Set Sum = 0.
4. Repeat the following:
a. If Sum > Limit, terminate the repitition, otherwise.
b. Increment Number by one.
c. Add Number to Sum and set equal to Sum.
5. Print Number and Sum.
Ex-3:
1. Declare variables: dividend, divisor, quotient
2. Prompt user to enter dividend and divisor
3. Get dividend and divisor
4. IF divisor is equal to zero, THEN
a. DO
i. Display error message, divisor must be non-zero
ii. Prompt user to enter divisor
iii. Get divisor
b. WHILE divisor is equal to zero
5. ENDIF
6. Display dividend and divisor
7. Calculate quotient as dividend/divisor \
8. Display quotient

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