Sunteți pe pagina 1din 24

Computer Programming & Utilization (GTU)

1-1

Introduction to Computer Programming

Chapter

1
1
Introduction to Computer & Programming
Introduction to Computer & Programming

Syllabus :

Programming Languages : Machine language, Assembly language, High level language, Compilers and interpreters

Problem Solving using computers : Algorithms and flowcharts

1.1 Introduction :

GTU - June 2010.

A Computer is divided into 2 categories - software and hardware. Hardware is the physical component of the computer, where as software is the logical component of the computer. The computer is intelligent device, where intelligence depends on the software. The comparison between hardware and software is given below.

Hardware Vs Software

Sr.

 

Hardware

 

Software

No.

 

1.

It

is

a

physical

component

of

the

It is logical component of the computer system.

computer.

 

2.

User

can

see

and

feel

the

hardware

User cannot see the logical components but can feel it.

components.

 

3.

Hardware is divided into 3 part that are microprocessor, mother board, and peripherals.

Software is divided into two categories that are system software and application software.

4.

Hardware is the electronics components. So it is designed by the electronics engineer.

Software is the collection of programs. So it is designed by computer engineer.

5.

For maintenance of the computer hardware , screw driver, tester, brush is required.

For maintenance of the computer software , testing software using set of input and output is required. Or they follow white box testing and Black box testing procedures.

Computer Programming & Utilization (GTU)

1-2

Introduction to Computer Programming

Sr.

Hardware

Software

No.

6.

For design of hardware, it requires special software(chip designing software).

For design of the software, programmer requires set of system software.

7.

Hardware is like car.

Software is like driver.

8.

Example are keyboard mouse, screen ,CPU , light pen, printer etc

Software are Microsoft word, paint brush , loader, linker etc.

1.1.1

Computer Hardware :

GTU - June 2009, Jan. 2010, June 2010.

It includes all physical components which are touchable and sensible. It is mainly divided into 4 parts - CPU, input device, output device and auxiliary memory.

CPU is the Central Processing Unit, which contains electronics circuits and used to execute instructions and also controls the operations of other input output devices. CPU is again divided into three parts ALU, CU, and memory .

addition,

subtraction, multiplication, division as well as logical operations like AND, OR,NOT operations.

ALU

(Arithmetic

and

Logical

Unit)

performs

arithmetical

operations

like

and Logical Unit) performs arithmetical operations like Fig. 1.1 : Block diagram of the computer Hardware

Fig. 1.1 : Block diagram of the computer Hardware system

Computer Programming & Utilization (GTU)

1-3

Introduction to Computer Programming

CU (Control Unit) controls each and every activity of processing of all connected devices. It acts as a brain. Its main function is to fetch instructions from main memory and execute it. Normally it executes instructions sequentially. But again this depends on specified instructions.

Memory is also called as a main memory or primary memory or internal memory. It is mainly used to store instructions or information in the form of zero’s and one’s. Control unit fetches instructions from the main memory. This memory is also called as a semiconductor memory because it is constructed by the semiconductor material like silicon. This memory is again divided into various types that are RAM, ROM, PROM, EPROM, EEPROM.

o

RAM (Random Access Memory) can hold data till power is on. So it is called as a

volatile memory (that means temporary memory).

o

ROM (Read Only Memory) can hold data permanently. Ordinary user can not store his

information into the ROM only manufacturer of the ROM chip can store data into it. It

consist of programs which can control IO devices (BIOS), booting procedures, programs

of some mathematical functions like sin, cos, tan etc. So it is called as a non volatile

memory (that means permanent memory).

o

PROM(Programmable Read Only Memory) can hold data permanently. Programmer

can store his information into the PROM but only once. After that modification is not

allowed. So it is called as a non volatile memory (that means permanent memory).

o

EPROM (Erasable Programmable Read Only Memory) can hold data permanently.

User can store his information into the EPROM but only once. After that bit

modification is not allowed. User can delete all the contents of the chip using ultra

violet rays and again rewrite information on the EPROM chip. So it is called as a non

volatile memory (that means permanent memory).

o

EEPROM (Electrically Erasable Programmable Read Only Memory) can hold data

permanently. User can store his information into the EEPROM and bit modification is

allowed. So it is called as a non volatile memory (that means permanent memory). But

till now it is not used as a secondary memory because of its cost.

CPU accepts information from user through input device. There are many input devices like

keyboard, mouse, mice, tracker ball, touch screens etc.

CPU conveys information to user through output device. There are many output devices like

monitor, LCD, printers, plotters, speakers etc.

Auxiliary memory is also called as a secondary memory or external memory or magnetic

memory. This is permanent memory. User can store data (programs or documents or

pictures etc.) permanently on this type of memory. It can be modified. There are many types

of secondary memory. That are hard disk, floppy disk, CDROM, pen drive etc.

Computer Programming & Utilization (GTU)

1-4

Introduction to Computer Programming

1.1.2 Computer Software :

GTU - June 2009 .

Program is the collection of instructions, which performs particular task, and collection of programs which accomplishes application (that means number of tasks) is called as a software. This software is classified into two categories - System software and Application software. System software directly interacts with computer hardware, whereas Application software is only designed to solve user problems as per users requirement. Following block diagram describes the roll of computer software and hardware.

describes the roll of computer software and hardware. Fig. 1.2 : Layers of the computer software

Fig. 1.2 : Layers of the computer software

System Software :

System software is classified into 3 categories : (1) Operating system (2) System support software and (3) System development software.

Operating system manages hardware as well as interacts with user, and provides different services to users. There are many operating systems like DOS, Windows-XP,VISTA, LINUX etc.

System support software manages hardware more efficiently, for example drivers of the IO devices or antivirus software’s

o

Drivers of the IO device consists of interfacing programs which can interacts with IO device. Every IO devices has its own driver programs.

o

Viruses are the programs which can start misuse of the resources thus there is mismanagement in the system. Virus infected systems lose their data as well as systems start doing some illegal operations.

o

Antivirus programs remove viruses from the systems and some time recover systems from major data loss.

System development software supports programming development environment to user. It include editor, pre-processors, compiler, interpreter, loader etc.

Computer Programming & Utilization (GTU)

1-5

Introduction to Computer Programming

o

Editor is the software , which is used to create programs as well as it is used for modification of existing programs.

o

Pre-processor is the software which is used before translators (that means compiler or editors) , which is used to replace some segments of code with some another segment. It is also called as an expansion.

o

Compilers are the software which can translate high level programs into programs.

low level

o

Interpreters are the software which can translate line by line high level programs into low level programs.

o

Loaders are the software which can load object codes into the main memory and execute it.

Compilers Vs Interpreters

Sr.

 

Interpreter

 

Compiler

No.

 

1.

Translates

and

executes

line

by

line

of

Translates whole source code into object code.

source code.

 

2.

User

can

see

the

result

of

program

at

User cannot see the result of program at translation time.

translation time.

 

3.

Interpreter is suitable for beginners.

 

Compiler is not suitable for beginners.

4.

It requires more memory because at the time of translation it places object code into main memory and executes it and produce the result.

It requires less main memory because at the time of translation it place object code into secondary memory. Execution is not the job of compiler. This is the job of loader.

5.

At first time the process of getting the results from source code is much faster than compilation because it not require loading time it requires only translation time.

At first time the process of getting the results from source code is slower than interpretation because it requires loading time for loading object code from secondary device to main memory for execution.

6.

It cannot produce any object code. Thus, it needs translation process for every execution.

Once object code is created then does not require translation, it only requires to load object code into the memory. That is loading process.

7.

So

this

process

is

lengthy

and

time

This process is faster than interpreter.

consuming.

 

8.

Debugging facilities can be easily provided by the interpreter.

When compiler provides debugging facility then logic becomes more complicated.

9.

Size of Interpreter program is larger than compiler because it contain two tasks translation as well as loading.

Size of compiler program is smaller than interpreter because it contain only translation procedure.

10.

Now

a

days,

there are two types of

Here portability can be achieved through bootstrapping process i.e. cross compilation of the object code.

interpreter that is pure interpreter and

impure interpreter. Impure interpreter becomes more popular because of their portability.

11.

Interpreters

easily

supports

dynamic

Compiler easily supports static allocation of

Computer Programming & Utilization (GTU)

1-6

Introduction to Computer Programming

Sr.

 

Interpreter

 

Compiler

No.

 
 

allocation of memory.

 

memory.

12.

Examples

:

Basic

interpreter,

P

code

Example : javac, gcc etc.

interpreter.

Application Software :

Application software is classified into two categories : General purpose software and Special purpose software.

General purpose software is used for many number of tasks, and provides many features for example word processor, oracle, excel etc.

Special purpose software is designed for specific purposes only. User programs comes under special purpose software for example pay roll system for specific company, tax calculation software etc.

Comparison of System Software with Application Software

Sr.

System software

Application software

No.

1.

Is primarily concerned with the efficient management of the computer system.

Is primarily concerned with the solution of some problems, using the computer as a tool.

2.

However system programs are intended to support the operation and use of the computer itself, rather than any particular application.

The focus is on the application, not on the computing system.

3.

Is usually related to the architecture of the machine on which that is to run.

Is usually related to the detailed knowledge of the Language and environment.

system programmer should have knowledge of computer architecture.

So that Application programmer should have detailed knowledge of high level programming language which is used to develop application program and environment i.e. operating system on which they are to run.

4.

Is machine dependent.

Is machine independent.

5.

Used to develop new system programs and using Bootstrapping we can make them portable.

Used to develop new application programs and using cross compiler i.e. again system programs, we can make them portable.

6.

Examples of system software are Assembler, linker, loader, compiler etc.

Examples of Application software are Paint, Photoshop, Microsoft access etc.

Computer Programming & Utilization (GTU)

1-7

Introduction to Computer Programming

1.2 Computer Languages :

Language is the media of communication. Natural languages contains many words with specific meaning and sentences with grammatical rules. Languages are used on computer system called as computer languages. Computer languages are divided into 2 categories - low level language, and high level language. Low level language is further divided into 2 types - machine language and assembly language.

1.2.1 Machine Language :

Computer directly understands this language. It is the language of 0’s and 1’s (which is also called as a binary number system i.e. binary pattern). Every instruction consists of order, data, address and all are in terms of 0’s and 1’s, thus it is very difficult to understand as well as remember.

1.2.1.1 Advantages of Machine Level Language :

The programs are compact and small.

The programs are stored in very less memory. Programmer can take care of each and every bits and bytes.

Once programs are entered into main memory computer can directly execute it without using any translator.

Suitable for low volume application, small simple program where the prototype is the final product.

It does not require any extra system program to run(like assembler).

1.2.1.2 Disadvantages of Machine Level Language :

The programs are difficult to understand or debug. (Address, instruction, and operands all are in machine language i.e. in binary pattern)

The programs are slow to enter since you must enter each bit individually

The programs do not describe the task, which you want to perform in anything resembling a human readable format.

The programs are long and tiresome to write.

The programmer often makes careless error. Which are subsequently very difficult to find (binary pattern all look the same.)

Programmer must have detailed knowledge of the architecture of particular microprocessor.

Machine language program are not portable.

1.2.2

Assembly Language :

Every machine language instruction is assigned to English word mnemonic such that it should describe function of instruction. Such language of mnemonics is called as Assembly language. Programs written in the assembly languages is called as an assembly language programs. Computer requires assembler to translate assembly level programs into machine level and then only it is become executable.

Computer Programming & Utilization (GTU)

1-8

Introduction to Computer Programming

1.2.2.1 Advantages of Assembly Level Language :

The assembly language instruction is called as mnemonic or memory jogger, which should describe in some way what the instruction does. (if we compare it with machine instruction.)

The programs are very easy to understand or debug.

The programs are fast to enter using alphanumeric keys of keyboard.

1.2.2.2 Disadvantages of Assembly Level Language :

Assembly language programs require assembler to translate assembly language program to machine level.

Programmer must have detailed knowledge of the architecture of particular microprocessor.

Programmers need to learn structure of assembly language program and syntax of every statement.

It requires assembler and loader for translation

Assembly language programs are not portable.

1.2.3

High level Language :

This language contains set of statements with each having their own syntactical (grammatical) rules. It is very similar to natural languages. Thus it is very easy for program development purpose. They requires set of system program for the execution of high level language program.

Example :- C, C++, JAVA, .NET (VB.Net, ASP.NET, C#.Net)

1.2.3.1 Advantages of High Level Language :

The High level instructions are easy sentences so it is very easy to learn. (if we compare it with machine instruction.)

Not need to learn computer architecture.

The programs are very easy to understand or debug.

The programs are fast to enter using alphanumeric keys of keyboard.

The programs are portable.

1.2.3.2 Disadvantages of High Level Language :

High level language program requires compiler or interpreter to translate high level language program to machine level that means object code.

Object code needs loader to load code into the main memory and execute that program.

Programmers need to learn structure of high level language program and syntax of every statement.

Some high level languages are environment dependent (That means dependent on operating system.)

Computer Programming & Utilization (GTU)

1-9

Introduction to Computer Programming

1.3 System Development Life Cycle :

Computer only understands the machine language, it is very difficult to write down the

programs, so now a days only high level languages are used to develop a program. But, directly

writing programs in the high level language is also a tedious work as they may produce wrong

result. To overcome such situation we need to follow program development process called as a

system development life cycle. This process is distributed in 6 phases, it is also called as a water

fall model which is shown in Fig. 1.3.

called as a water fall model which is shown in Fig. 1.3 . Fig. 1.3 :

Fig. 1.3 : Waterfall model

System Requirement : This phase includes understanding the problem, and think on what exactly has to be done. Gather all information which is essential to solve problem.

Analysis : In this phase all gathered information is analyzed by different alternatives depending upon the available resources.

Design : In this phase, start to solve problem using various tools like flowcharts and algorithms which are explained in the section 1.4. It is very important step which helps in showing the flow of the program as well as detecting mistakes if any.

Coding : Finally all the design is to be converted into the coding (i. e. programs).

Testing : It is again very important phase, which is used to test whether output of the program is correct or not? This can be tested with various set of inputs.

Maintenance : In this phase, program is compared with initial requirement, and as per requirements, new features are added into it.

1.4 Algorithms :

.GTU Jan. 2010, June 2010 .

An algorithm is the finite set of sequential instructions to accomplish a task, where instruction are written in the natural languages like English. It is also called as a step by step solution of the problem.

Computer Programming & Utilization (GTU)

1-10

Introduction to Computer Programming

Note :

Always remember that algorithm and flowcharts are to be developed first and then programs are to be written.

1.4.1 Properties/Characteristics of the Algorithm :

Algorithm has four properties, that are finiteness, definiteness, effectiveness, input and output. They are explained below.

Finiteness : Total number of steps used in algorithm should be finite.

Definiteness : Each step of algorithm must be clear and un ambiguous.

Effectiveness : Every step must be basic and essential.

Input and output : The algorithm must accept zero or more input and must produce at least one output.

1.4.2

Advantages :

Very easy to write.

Easy technique to understand logic.

Easy identification of the mistakes by non computer person.

1.4.3

Disadvantages :

Time consuming.

Difficult to show branching and looping.

Big tasks are difficult to put in algorithm.

1.4.4

Examples of Algorithm :

Simple Flow Problem : These are very simple problems, and the procedure of flow is in sequential manner, means after first step, it automatically goes to second step.

Example 1 :

Write an algorithm to calculate area of rectangle.

Algorithm

Step 1

: Accept the value of length i.e. l

Step 2

: Accept the value of Breadth i.e. b

Step 3

: Calculate area i.e. a=l*b

Step 4

: Print Area i.e. Print a

Step 5

: Stop procedure

Example 2 :

Write an algorithm to calculate percentage of the student.

Algorithm

Step 1

: Accept the name and marks in 6 subject, i.e. n,m1,m2,m3,m4,m5,m6

Computer Programming & Utilization (GTU)

1-11

Introduction to Computer Programming

Step 3

: Calculate percentage i.e. per=Total/600*100

Step 4

: Print percentage i.e. Print per

Step 5

: Stop procedure

Branching Flow problems : These sentences are not simple. It consists of condition, it tests that condition , according to it transfers the flow. Here flow is not sequential that means after branching step, it automatically goes to step mentioned in the statement.

Example 3 :

Write an algorithm to check whether the given number is positive or negative?

Algorithm

Step 1

: Accept the number i.e. n

Step 2

: Check if n<0 ? If yes go to Step 3 otherwise go to Step 5

Step 3

: Print n is negative

Step 4

: Stop procedure

Step 5

: Print n is positive

Step 6

: Stop procedure

Example 4 :

Write an algorithm to find out smallest number out of two numbers.

Algorithm

Step 1

: Accept two numbers i.e. a , b

Step 2

: Check if a<b ? If yes go to Step 3 otherwise go to Step 5

Step 3

: Print a is smallest number

Step 4

: Stop procedure

Step 5

: Print b is smallest number

Step 6

: Stop procedure

Example 5 :

Write an algorithm to find out largest number out of four numbers.

Algorithm

Step 1

: Accept four numbers i.e. a , b , c ,d

Step 2

: Check if a>b ? If yes Go to Step 3 otherwise go to Step 14

Step 3

: Check if a>c ? If yes Go to Step 4 otherwise go to Step 9

Step 4

: Check if a>d ? If yes Go to Step 5 otherwise go to Step 7

Step 5

: Print a is largest number

Step 6

: Stop procedure

Step 7

: Print d is largest number

Step 8

: Stop procedure

Computer Programming & Utilization (GTU)

1-12

Introduction to Computer Programming

Step 10 :

Print c is largest number

Step 11 :

Stop procedure

Step 12 : Print d is largest number

Step 13 : Stop procedure

Step 14 : Check if b>c ? If yes Go to Step 15 otherwise go to Step 20

Step 15 : Check if b>d ? If yes Go to Step 16 otherwise go to Step 18

Step 16 :

Print b is largest number

Step 17 :

Stop procedure

Step 18 : Print d is largest number

Step 19 : Stop procedure

Step 20 : Check if c>d ? If yes Go to Step 5 otherwise go to Step 23

Step 21 :

Print c is largest number

Step 22 :

Stop procedure

Step 23 : Print d is largest number

Step 24 : Stop procedure

Above algorithm is structured algorithm (that means nesting). We can eliminate repetitive steps using unstructured way, which is described in following algorithm.

Step 1

: Accept four numbers i.e. a , b , c ,d

Step 2

: Check if a>b ? If yes Go to Step 3 otherwise go to Step 12

Step 3

: Check if a>c ? If yes Go to Step 4 otherwise go to Step 9

Step 4

: Check if a>d ? If yes Go to Step 5 otherwise go to Step 7

Step 5

: Print a is largest number

Step 6

: Stop procedure

Step 7

: Print d is largest number

Step 8

: Stop procedure

Step 9

: Check if c>d ? If yes Go to Step 10 otherwise go to Step 7

Step 10 : Print c is largest number

Step 11 : Stop procedure

Step 12 : Check if b>c ? If yes Go to Step 13 otherwise go to Step 9

Step 13 : Check if b>d ? If yes Go to Step 14 otherwise go to Step 7

Step 14 : Print b is largest number

Step 15 : Stop procedure

Computer Programming & Utilization (GTU)

1-13

Introduction to Computer Programming

Dear students, You can see that both algorithms produce accurate and same result but

algorithm 2 requires less number of steps. When you are solving any problem first time then do

not think about steps only try to produce accurate result and then try to reduce unnecessary as

well as repetitive steps.

LOOPS : There are 2 types of loops : Finite loop and Infinite loops

When number of steps are repeated many number of times using same sequence is called as

a loop and set of repeated steps are called as a body of loop.

Finite Loops : When body of loop is executed finite number of times called as finite loop. For construction of finite loops following steps are important

Step 1

: Initialize (count) running variable with initial value I=1

Body of loop

Step 2

: Increment running variable by step value. I=I+1

Body of loop

Step 3

: Check and transfer control to step 2 or in between step 1 and 2 (i.e. body of loop) If

I<10(some final value) then step 2

Note :

When initial value is less than final value then step value should be positive.

Note :

When initial value is greater than final value then step value should be negative.

Note :

Step value should not be zero.

Note :

Running variable should not be initialised by some constant within the body of loop.

Note :

Running variable should not be same in nested loops (i.e. loop within loop)

Example 6 : Write an algorithm to print first 50 odd numbers.

There are two possible algorithms

Algorithm1

Algorithm2 (Last odd number is 99)

Step 1 : I=1

Step 1 : I=1

Step 2 : ODD=1

Step 2 : Print I

Step 3 : Print ODD

Step 3 : I=I+2

Step 4 : ODD=ODD+2

Step 4 : If I <=99 go to step 2

Step 5 : I=I+1

Step 5 : Stop procedure

Step 6 : If I <=50 go to Step 3

Step 7 : Stop procedure

Computer Programming & Utilization (GTU)

1-14

Introduction to Computer Programming

Example 7 : Write an algorithm to find sum and average of given N numbers.

Example 8 : Write an algorithm to find out factorial of given number.

Algorithm

 

Algorithm

 

Step 1

: Accept N

Step 1

: Accept N

Step 2

:

I=1

Step 2

:

I=1

Step 3

: SUM=0

Step 3

: FACT=1

Step 4

: Accept any number i.e. A

Step 4

: FACT=FACT*I

Step 5

: SUM=SUM+A

Step 5

: I=I+1

Step 6

: I=I+1

Step 6

: If I<=N go to Step 4

Step 7

: AVG=SUM/N

Step 7

: Print FACT

Step 8

: Print SUM

Step 8

: Stop procedure

Step 9

: Print AVG

 

Step 10 : Stop procedure

Example 9 : Write an algorithm to solve following series. 1-x+x 2 -x 3 ---x n

Algorithm

Step 1

: Accept N, X

Step 2

: I=1

Step 3

: SUM=1

Step 4

: SIGN=-1

Step 5

: TERM=SIGN * X I

Step 6

: SUM=SUM+TERM

Step 7

: SIGN=SIGN*-1

Step 8

: I=I+1

Step 9

: If I<=N go to Step 5

Step 10 : Print SUM

Step 11 : Stop procedure

Infinite Loop : When the body of loop is executed finite number of time called as finite loop. Following algorithm is the example of infinite loop.

Computer Programming & Utilization (GTU)

1-15

Introduction to Computer Programming

Example 10 :

Write an algorithm to print “Tech Max Publication Jindabad” infinite times.

Algorithm

Step 1

: Print “Tech Max Publication Jindabad”

Step 2

:

Go to Step 1

Step 3

: Stop procedure

Here step 3 never executes, so it is called as dead step

1.5 Flowcharts :

.GTU Jan. 2010, June 2010 .

A Flowchart is pictorial representation of algorithm.

Symbol

Name

 

Uses

 
Start and Stop Symbol Used to start flow chart as well as to terminate the

Start and Stop Symbol

Used to start flow chart as well as to terminate the flow chart.

 
Input /Output Used for IO operation  

Input /Output

Used for IO operation

 
  Used to mention ALU and data
 

Used to mention ALU and data

Process

transfer

task

(i.e.

arithmetic

or

assignment task)

 
Decision For branching condition  

Decision

For branching condition

 
Flow lines Indicates flow  

Flow lines

Indicates flow

 
Loop Indicates finite loop  

Loop

Indicates finite loop

 

Fig. 1.4 contd

Computer Programming & Utilization (GTU)

1-16

Introduction to Computer Programming

Symbol

Name

Uses

Connector Connecting flow lines from different places

Connector

Connecting flow lines from different places

Multiple selection For multiple branching condition

Multiple selection

For multiple branching condition

Block Indicates block of statements or body of loop

Block

Indicates block of statements or body of loop

Module call Calling the subroutine or function

Module call

Calling the subroutine or function

Fig. 1.4 : Flowcharting symbols

1.5.1

Advantages :

Easy to draw.

Easy technique to understand logic.

Easy to identify the mistakes by non computer person.

Easy for branching and looping.

1.5.2

Disadvantages :

Time consuming.

Difficult for modification.

Difficult task to draw flow charts for big programs.

Computer Programming & Utilization (GTU)

1-17

Introduction to Computer Programming

1.5.3 Examples of Flowchart :

Example 11 : Draw a flowchart to calculate area of rectangle.

Example 12 :

Draw a flowchart to calculate

percentage of the student.

Flowchart :

Flowchart :

percentage of the student. Flowchart : Flowchart : Fig. 1.5   Fig. 1.6 Example 13 :
percentage of the student. Flowchart : Flowchart : Fig. 1.5   Fig. 1.6 Example 13 :

Fig. 1.5

 

Fig. 1.6

Example 13 : Draw a flowchart to check whether the given number is positive or negative ?

Example 14 :

Draw a flowchart to find out

smallest number out of two numbers.

Flowchart :

Flowchart :

Draw a flowchart to find out smallest number out of two numbers. Flowchart : Flowchart :
Draw a flowchart to find out smallest number out of two numbers. Flowchart : Flowchart :

Fig. 1.7

 

Fig. 1.8

Computer Programming & Utilization (GTU)

1-18

Introduction to Computer Programming

. GTU - Dec. 2008.

.GTU - Dec. 2008.

. GTU - Dec. 2008.

Flowchart :

to Computer Programming . GTU - Dec. 2008. Flowchart : Fig. 1.9 Example 16: Draw a

Fig. 1.9

Example 16: Draw a flowchart to find out sum and

Example 17 : Draw a flowchart to find out factorial of given N numbers.

average of given N numbers.

.GTU - Dec. 2008.

 
   

GTU - April 2010.

 

Flowchart :

Flowchart :   Flowchart :  
 

Flowchart :

Flowchart :
 

Fig. 1.10

Fig. 1.11

Computer Programming & Utilization (GTU)

1-19

Introduction to Computer Programming

Example 18 : Draw a flowchart to solve following series.

1-x+x 2 -x 3 +---x n

Flowchart :

following series. 1-x+x 2 -x 3 +---x n Flowchart : Fig. 1.12 Example 19 : numbers.

Fig. 1.12

Example 19 :

numbers.

Draw a flowchart to print first 50 odd

.GTU April 2010.

Flowchart :

to print first 50 odd . GTU – April 2010 . Flowchart : Fig 1.13 Example

Fig 1.13

Example 20 : Draw a flowchart to print “Techmax jindabad” infinite times.

Flowchart :

. Flowchart : Fig 1.13 Example 20 : Draw a flowchart to print “Techmax jindabad” infinite

Fig 1.14

Computer Programming & Utilization (GTU)

1-20

Introduction to Computer Programming

Example 21 :

Write an algorithm and draw flowchart for finding sum digits of a number.

Algorithm :

Flowchart :

Step 1

: Accept N

Step 2

: N1=N,SUM=0

Step 3

: D=N%10

Step 4

: SUM=SUM*D

Step 5

: N=N/10

Step 6

:

If N !=0 go to Step 3

Step 7

: Print SUM

Step 8

: Stop procedure

: N=N/10 Step 6 : If N !=0 go to Step 3 Step 7 : Print

Fig. 1.15

Computer Programming & Utilization (GTU)

1-21

Introduction to Computer Programming

Example 22 :

Write an algorithm and draw the flowchart of a program to find the maximum of 'n' numbers.

Algorithm :

Step 1

: Accept N

Step 2

: Accept FIRSTNUM

Step 3

: I=2 , MAX=FIRSTNUM

Step 4

: Accept any number i.e. A

Step 5

: Check if A>MAX Then MAX=A

Step 6

: I=I+1

Step 7

: If I<=N go to Step 4

Step 8

: Print Maximum number is MAX

Step 9

: Stop procedure

Flowchart :

number is MAX Step 9 : Stop procedure Flowchart : Fig. 1.16 Example 23 : Write

Fig. 1.16

Example 23 :

Write an algorithm and draw the flowchart to accept N numbers and count how

 

many of them where odd and also compute sum of all these odd.

.GTU June 2010.

 

Ans. :

Step 1 :

COUNT=1 : ODD=0: SUM=0

Step 2 :

Accept N

Step 3 :

Accept A

Step 4 :

If A%2==1

Then

SUM=SUM+A

Computer Programming & Utilization (GTU)

1-22

Introduction to Computer Programming

ODD=ODD+1

Step 5 :

COUNT=COUNT+1

Step 6 :

If COUNT<=N Then Go to step 2

Step 7 :

Print COUNT and SUM

Step 8 :

Stop Procedure

Flowchart :

COUNT and SUM Step 8 : Stop Procedure Flowchart : Exercise Q. 1 Explain the block

Exercise

Q.

1

Explain the block diagram of the computer.

Q.

2

Differentiate between system programs and application program.

Q.

3

Differentiate between compilers with interpreter.

Q.

4

What are the advantages and disadvantages of machine languages?

Q.

5

What are the advantages and disadvantages of high level languages?

Q.

6

Differentiate between software and hardware.

Q.

7

What is algorithm and flowchart ? and why it is used ?

Computer Programming & Utilization (GTU)

1-23

Introduction to Computer Programming

1.6 University Questions and Answers :

Dec. 2008

Q.

1

Draw a flow chart to find the maximum number out of three given numbers.

 

(Pg. 1-23, Example 15 : Say d = 32768 (Smallest integer number))

(5 Marks)

Q.

2

Draw a flow chart to do the sum of 10 elements read from the user. (Pg. 1-24, Example 16 : say n = 10)

(5 Marks)

 

June 2009

 

Q.

3

Draw block diagram of computer and explain each block. (Section 1.1.1)

(7 Marks)

Q.

4

Define following :

 
 

(i)

Operating system

(ii)

Compiler

(iii)

Application software

(iv)

System software (Section 1.1.2)

 

(4 Marks)

 

Jan. 2010

 

Q.

5

Draw the Block Diagram of Computer Architecture and explain each block with its functions.

 

(Section 1.1.1)

 

(7 Marks)

Q.

6

Give comparison of Flow charts and Algorithms (Sections 1.4 and 1.5)

(4 Marks)

 

April 2010

 

Q.

7

Draw a flow chart to find factorial of a given number. (Section 1.5)

(5 Marks)

 

June 2010

 

Q.

8

Provide two major differences between

 
 

(a)

Software and Hardware

(Section 1.1)

 

(b)

Flowchart and Algorithm

(Section 1.4 and 1.5)

Q.

9

Name the major components of computer and give their function in brief. (Section 1.1.1)

(2 Marks)

Q.

10

Write an algorithm and draw the flowchart to accept N numbers and count how many of them where odd

and also compute sum of all these odd. (Example 23)

(10 Marks)



Computer Programming & Utilization (GTU)

1-24

Introduction to Computer Programming

Note
Note