Download as pdf or txt
Download as pdf or txt
You are on page 1of 13

EST 102 Programming in C

MODULE I
3 Marks
1. Differentiate between system software and application software

System software Application Software


Used for operating computer Used to perform a specific task
hardware
Installed on the computer when OS Installed according to user
installed requirements
User does not interact with system User interacts with application
software software
because it works in the
bacckground
System software can run It cant run independently,they cant
independently.Provides platform run without the presence of system
for running application software software
Eg:Compiler,Assembler,debugger Eg:Word processor,web browser

2. Write an algorithm to find the largest of three numbers


Step 1-start
Step 2-Declare variables a,b and c
Step 3- Read a,b and c
Step 4- if a>b and a>c goto step 5.else go to step 6
Step 5- print a
Step 6- if b>c go to step 7 else go to step 8
Step 7- print b
Step 8- print c
Step 9- stop

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

3. Describe the memory hierarchy of a computer with the help of a diagram


Memory is the place where data and instructions are stored for the
execution by the CPU.Memory is classified into 3 –cache memory,primary
memory and secondary memory.
a. Cache memory:It is a high speed memory place in between RAM and
CPU.They are used more often,and make available to CPU at a faster
rate.Caches are of two types L1 cache and L2 cache.When the
computer seeks data it is this memory which is checked first and if
data not available,data is taken out of the disk.
b. Primary memory:( (RAM &ROM):Primary memory is used to store
data and instructions during the processing of the data.Primary
memory is of 2 types-RAM and ROM.
RAM(Random Access Memory):These memories can be instantly
changed.It holds programs and data while they are in use.It needs a
constant supply of power to retain the information.It is a volatile part of
the memory.RAM act as high speed between hard disk and the
processor.The amount of RAM available determines the size and power
of programs.Two main types of RAM are Static RAM(SRAM) and
Dynamic RAM(DRAM).
ROM(Read only memory):It is a non volatile memory.It is permanent
in nature and is used for storing programs that permanently reside in
computer.ROM contains a set of start up instructions to ensure the
memory is functioning properly and checks for peripheral device as well
as operating systems.ROM on which user can alter the programs are
called (EPROM-Electrically programmable read only memory).
c. Secondary memory:Stores data and instruction permanently.Information
can be stored for a long time and is non volatile.Eg:Floppy disk<CD,DVD
etc

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

4. What is the purpose of flow charts in problem solving? Draw a flow chart
to find the largest of three numbers.
Flowchart is a diagrammatic representation of an algorithm. It can
help to organize big-picture thinking and provide a guide when it comes time
to code. More specifically, flowcharts can: Demonstrate the way code is
organized. Visualize the execution of code within a program.
FLOW CHART

5. What are the functions of ALU and CU?


Arithmetic logic unit(ALU):It is responsible for processing data
andinstructions.When the control unit encounters instructions for performing
arithmetic operations it passes information
to ALU.
Control Unit(CU):It supervises overall operation of other units of a
computer.It fetches instruction and data from memory unit and execute
instructions one at a time using time
signal.

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

6. Differentiate between complier and interpreter.


Compiler Interpreter
Considers the completion of Considers only one statement in
program as input for converting to program at a time as input for
machine code converting to machine code
Usually generate intermediate code Doesn’t create an intermediate
in the form of object file(.obj) object
Faster execution of control Slower execution of control
statements statements
Detected errors in the program get Detected errors in the program get
displayed after the entire program displayed after each instruction
is read by compiler read by interpreter
Eg:C++,Java Eg:BASIC,Python

7. Differentiate between High level language and Low level language


High level language Low level language
Programmer friendly Machine friendly
Less memory efficient High memory efficient
Easy to understand Difficullt to understand

Simple to debug Complex to debug


Simple to maintain Complex to maintain
Portable Non portable
Can run on any platform Run only on specific target
platform for
which it is developed
Needs compiler or interpreter for Needs assembler for translation
translation

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

8. Draw a flowchart to find the sum of first N numbers.

9. What is register?What are its types?


Registers: Registers are high speed storage areas within CPU but has
least storage capacity.these are directly accessed and manipulated by
CPU during instruction execution.
Registers are classified into
Accumulator:Most frequently used register to store data from memory.
Memory Data Register(MDR):It contains data to be written or read to
memory.
Memory Address register(MAR):It holds the address of the location to
be accessed from memory.
Program Counter(PC):It is used to keep track of execution of the
program and contains memory address of the next instruction to be
fetched.

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

Instruction register(IR):It is the register which holds the instruction


which is currently been executed.

7 Marks/14 Marks PART B Questions

10. Draw a flowchart to find the factorial of a number.

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

11. With the help of a neat diagram explain the functional units of a
computer

Input unit:Consist of different input devices.Input is taken in the form of


clicks,drags,pointing etc. eg –keyboard,mouse, joystick etc
Processing unit:It consist of various parts like CU(control
unit),ALU(Arithmetic logic unit),Regsiters.CPU perform operations like
addition,subtraction,division and produce output.
Components of a processing unit:
a)ALU, b)CU, c)Registers (Refer Qn 5&9)
d)Memory Unit:It is the place which provides data to CPU for
processing.(Refer Qn 3)
e.)Storage unit:It is a non volatile device that holds program,files and
documents.
f.)Output Unit:These are the collection of hardware components that
show ouotput to the user either in hard copy or a soft copy format

12. Write algorithm and draw flowchart to perform swapping of two


numbers.
Step 1- start
Step 2 - declare three variables N1, N2 and TEMP Initialise to 0
Step 3 -Read input in N1 and N2, say N1 = 5 and N2 = 7
Step 4- Assign the value of N1 to TEMP, say 5
HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram
EST 102 Programming in C

step 5-Now TEMP = 5 and N1 = 5


step 6- Put the value of N2 in N1, so N2 = 7 and N1 = 7
step 7- Then, put the value of TEMP in N2, so TEMP = 5 and N2 =
5
step 8 –stop

Flowchart

13. Draw the flowchart of bubble sort. Trace the steps for the input
[5,3,1,7,9].

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

5,3,1,7,9 (complete explation as in your notebook)


Bubble sort algorithm/Pseudo code( write if asked in Question)
Step 1 start
Step 2- Declare variables a[20], i,temp=0
Step 3- Read n as size of array
Step 4- for i=0,i<n repeat step 5 else go to step 6
Step 5 read a[i], and i++
Step 6 - i=0
Step 7 – for i<n-1 goto step8 else goto step 14
Step 8 –j=0
Step 9- for j<n-1-i, goto step 10 else goto step 13
Step 10- if a[j]>a[i+1], goto step 11 else goto step 12
Step 11 swap a[j] and a[j+1]
Step 12 – j++ and goto step 9
Step 13- i++ and goto step 7
Step 14-stop
14. Write an algorithm for linear search. Demonstrate the working for
the given array 23,34,41,65,70 and element to be searched is 65

Algorithm or Pseudo code for linear search(anser if asked in qn)


Step 1. Start
Step 2. Read the limit n
Step 3. Read the number to be search num
HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram
EST 102 Programming in C

Step 4. i=0
Step 5. if(i<n) then goto step 6 else goto step 8
Step 6. Read the number A[i]
Step 7. i=i+1, then goto step 5
Step 8. i=0
Step 9. if(i<n) then goto step 10 else goto step 11
Step 10. if(A[i]==num) then print number is present at location i+1and goto
step 12, else i=i+1 and goto step 9
Step 11. If i==n print the num is present
Step 12- stop

In this Qn there is to explain Working of eg array 23,34,41,65,70

declare array a[20],n,I,num


read limit n=5
for(i=0,i<n)scan every element in array and i++
so 5 elements are inserted in array
read num as 65
(for i=0,i<n check if a[i]==num.)
First i=0,i<5 a[0]=23 which is not equal to 65 so i=i++,
Now i=1,i<5,a[1]=34 which is not equal to 65 so i++
Now i=2 , i<5 a[2]=41 which is not equal to 65 so i++
Now i=3 , i<5 a[3]=65 which is not equal to 65 so i++
Now i=4 , i<5 a[4]=70 which is not equal to 65 so i++
Now i=5 , I not<5 so end for loop
Check if (i=n)
Here i=5 and n=5. So program will print num(65) is not present in array

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

Flowchart for linear search (Answer if asked)

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram


EST 102 Programming in C

15. WriteAlgorithm and flowchart of sum of digits of a number


(Answer if asked both.Else answer to the Qn )

Flowchart

Algorithm
Step 1- start
Step 2 – read n
Step 3- sum=0
Step 4- if n>0 go to step 5,else go to step 6
Step 5- temp=n%10, sum=sum+temp, n=n/10 and goto step 4
Step 6- print sum
Step 7 - stop

HARSHIYANAS M, Dept of CSE,KMCTITM Kuttippuram

You might also like