










































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
The concept of functions in C language, focusing on the differences between library functions and user-defined functions. It covers the syntax and examples of various types of functions, including those with no input and no return value, input and no return value, input and return value, and recursive functions.
Typology: Lecture notes
1 / 50
This page cannot be seen from the preview
Don't miss anything!











































Computer Science Questions and Answers UNIT-A Chapter - 1 Configuring a Computer
I One Mark Question and Answer
1. Name the components of CPU Ans. a) ALU b) PC c) Accumulator d) MAR e) IR f) ID g) MDR 2. What is the use of registers in CPU? Ans. It is used to store intermediate data and instructions. 3. What is the function of MAR? Ans. It specifies the address of memory location from which data or instruction is to be accessed or to which the data is to be stored. 4. What is the function of MDR / MBR?
Ans. It contains the data to be written into or read from memory location addressed by MAR.
5. What is program counter?
Ans. It keeps track of the memory address of the instruction that is to be executed next.
6. What is the function of IR?
Ans. It contains the instruction that is being executed.
7. What is the purpose of Instruction Decoder?
Ans. It decodes the instructions.
8. What is a data bus?
Ans. It carries a word to or from memory.
9. What is an address bus?
Ans. It carries memory address. The width of address bus equals the number of bits in the MAR.
10. What is the function of control bus?
Ans. It carries signals between the units of the computer.
11. Name different I/O ports.
Ans. Port is a socket on the back of computer. Different types of ports are serial ports, parallel ports and USB ports.
12. What is meant by plug and play cards?
Ans. It enables the user to add devices to computer.
13. Expand SD RAM.
Ans. Synchronous Dynamic Random Access Memory.
14. Expand DDR RAM.
Ans. Double Data Rate Random Access Memory. II Two Marks Questions.
1. Explain USB Port (Universal Serial Bus).
Ans. a. It is a high speed serial bus b. It is a plug and play interface between computers and add on devices.
2. Give the specifications of Laser printer.
Ans. a. Resolution varies from 600 to 1200 dots per inch. b. Speed varies from 4 PPM to 24 PPM. c. Buffer size varies from 4MB to 32 MB d. Can print color images.
3. Give the specifications of dot matrix printer.
Ans. a. Print head normally has 9 pins to 24 pins. b. Speed varies from 30 to 300 characters per second. c. Buffer size varies from 1K to 64 K.
4. Give the specifications of inkjet printer.
Ans. a. Resolution is around 300 dots per inch. b. Speed varies from 1PPM to 12 PPM c. Buffer size varies from 1 MB to 4 MB.
III Five Marks Questions:
1) Write a note on computer maintenance.
Ans : a. Avoid heat dust and noise b. Periodic updates and enhancements c. Installing fire walls and anti virus. d. In house software maintenance e. Computer periodic checkup. 2) What are the possible threats to a computer system and how to provide security?
Ans : Threats a. Privacy b. Integrity c. Environmental damage d. Human threats e. Software threats f. Unauthorized access g. Computer viruses Security a. Physical protection of machine and media. b. Giving passwords and users ID c. Using Licensed software d. Use of Cryptography e. Use of Spike busters and UPS 3) Explain the typical causes of computer failures.
Ans: a. Break down of components. b. Excessive dust or humidity c. Virus d. Voltage fluctuation
Ans : Program counter: This register stores address of next instruction to be executed. Memory address register (MAR): This register specifies address in memory where information can be found. This register is also used to point to a memory locations where information can be stored.
Memory buffer register: This register acts as an interface between CPU and memory. When CPU issues a Read Memory command, instruction is fetched and placed in MB register.
Instruction register -This stores a copy of current instruction.
Instruction decoder (ID): ID is an electronic hardware, which decodes instructions. The instructions are further broken down into a set of micro operations, so that they can be executed directly.
General purpose registers: They are used to store data. There are 6 GP registers. These are used for storage of data as needed by the program. Arithmetic logic unit: The basic arithmetic operations such as addition,subtraction,multiplication and division are carried out here. These operations need atleast two operands, one which is stored in accumulator and the other in the MBR. After the manipulation of data in ALU, the result is transferred to accumulator. Accumulator : During processing the intermediate data needed for future processing is stored in accumulator. The contents of ACC are used by ALU for operations and later by MBR holds the final result for further action.
Chapter - 2 Problem Solving Techniques UNIT-B
I One Mark Question and Answer
1) Define Sorting.
Ans. Sorting is a method of arranging data items in any order.
2) What is searching?
Ans: It is a process of locating an element stored in a file.
3) Mention the different structured programming constructs.
Ans: a. Sequence b. Selection c. Iteration 4) What is stepwise Refinement?
Ans: Is a process of breaking down the problem at each stage to obtain a solutions.
5) Name the different searching methods.
Ans: a. Linear Search b. Binary Search 6) Define module.
Ans: It is an independent set of statements, which can be called in another program.
7) What is the main advantage of linear search method?
Ans. It is simple and useful when the elements to be searched are not in any definite order.
8) What is the other name of bubble sort?
Ans: The bubble sort method is also called as sorting by exchange.
9) What is structured programming?
Ans: It is a method of using the concept of sequence , selection , iteration and modularity.
10) Name the searching technique which requires sorted elements.
Ans: Binary Search.
11) What is top-down analysis?
Ans: Solving a problem by breaking it up into smaller parts is called as top-down analysis.
12) What is top-down approach called as?
Ans: Top-down analysis is also called as stepwise refinement
13) What is a module?
Ans: Each program segment is called a module.
b. Structured programs are easy to test and debug.
III Five Marks Questions and Answers:
1) Mention the objectives of structured programming.
Ans: a. To produce error free program. b. To incorporate basic structured constructs. c. To eliminate use of GOTO Statements. d. To obtain a disciplined approach towards programming. e. To improve the flexibility of a program. 2) Explain top-down analysis with an example.
Ans: The approach of dividing a problem into sub problems and dividing the sub problems until a solution is obtained is called top-down analysis. Ex:
3) Write an algorithm to sort an elements using Insertion Sort. Ans: Algorithm for Insertion sort Step 1 : START Step 2 : Input N Step 3 : for I← 0 to N - Read A [ I ] ( end of I for loop ) Step 4 : For I ← 1 to N -1 Do Step 5 : J = I Step 6 : While ( J > = 1 ) and ( A[ J ] < A [ J -1 ] ) Step 7 : TEMP = A [ J ] Step 8 : A [ J ] = A [ J - 1 ] Step 9 : A[ J - 1 ] = TEMP Step 10 : J = J - 1 [ end of While loop ] [ end of step I For loop ] Step 11 : for I ← 0 to N - Step 12: Print A [ I ] Step 13 : Stop
Consider the elements A[0 ] A[1] A[2] A [3]
20 16 4 3
Process Output
SI ← ( P * T * R ) 100
Input
SIMPLE INTEREST
P T R (^) SI P^ T (^) R
Pass 1: A[1],A[0]>16,20,4, Pass 2: A[2],A[1]> 16,4,20, A[1],A[0]>4,16,20, Pass 3: A[3],A[2]> 4,16,3, A[2],A[1]>4,3,16, A[1],A[0]> 3,4 16,
Sorted order is 3,4,16,
4) Explain bubble sort algorithm with example.
Ans: Algorithm for bubble sort Step 1 : START Step 2 : Input N Step 3 : for I← 0 to N - Step 4 : Read ( A [ I ] ) ( end of for loop ) Step 5 : for I← 1 to N - Step 6 : for J ← 0 to N –I - 1 Step 7 : If (A[ J ] > A [ J +1] ) Temp ← A [ J ] A [ J ] ← A [ J + 1 ] A [ J +1 ] ← Temp [ end of if ] [ end of J loop ] [ end of I loop ] Step 8 : for J ← 0 to N - Print A [ J ] Step 9 : Stop Consider the following elements: 50 , 20, 10 , 05 Pass 1 Pass 2 Pass 3 50 20 20 20 10 10 20 50 10 10 20 05 10 10 50 05 05 20 05 05 05 50 50 50
Sorted order is 5, 10, 20 , 50 5) Explain selection sort with an example.
Ans: Slection sort is based on finding the smallest element in the list and placing it at the first position. Then the next element is found and placed at the second position and so on. Consider the elements 20,16,4, Pass 1: 20 3 16 16 4 4 3 20
Step 9: High ← M – 1 Step 10 : Else Step 11 : Low ← M + 1 [ end of if ] [ end of While loop ] Step 12 : if ( Loc > = 0 ) Then Step 13: Print “ ele , found , search successful ” , Loc Step 14: else Step 15 : Print “ Item not found , search Unsuccessful ” [ end if ] Step 16 : Stop
7) Write the steps involved in performing binary search operation to search an element 56 in the following numbers.
Ans: a.
0 1 2 3 4 5 6 Assuming ‘ a’ is the name of the array
initial values:
n = 7 low = 0 high = n – 1 = 6 mid = [ low + high ] / 2 = ( 0 + 6 ) / 2 = 3 S = 56 [ search element ] a [ mid ] = 67 Step 1 : Compare the element in a [ mid ] and search element 56 67 is not equal to 56 Step 2 : Check whether search element comes after or before the mid index element Since 56 < 67 [ The search element is lesser than 67 , then the search element lies to the left of mid point ] Step 3 : Change high = mid – 1 = 3 – 1 = 2 mid = ( low + high ) / 2 = ( 0 + 2 ) / 2 = 1 Step 4 : Compare a [ mid ] and S for equality Step 5 : Since 56 is greater than 48 [ If ( S > a [ mid ] ) i.e. 56 > 48 ] Step 6: Change low = mid + 1 = 1 + 1 = 2 mid = ( low + high ) / 2 = ( 2 + 2 ) / 2 = 2 Step 7: Compare a [ mid ] and S for equality. Since S and a [ mid ] are equal search is successful and the element is found at the location mid i.e. 2
32 48 56 79 82 99
32 48 56 67 79 82 99
8) Write an algorithm to find the maximum in an array
Ans: Step 1 : [Assume 1st^ element is the largest ] large = A [ 0 ] Step 2 : POS = 0 Step 3 : [ Find the largest element in the array and its position] For I = 1 to N – 1 Do Step 4 : If ( A [ I ] > large ) Then Step 5 : large = A [ I ] Step 6 : POS = 1 [ End if ] [ End of step 3 for loop ] Step 7: [ Print the largest and its position] Print “ Largest = “ , large , “ position = “ , pos Step 8: Exit 9) Write an algorithm to find the minimum in an array
Ans: Step 1 : [Assume 1st^ element is the smallest] small = A [ 0 ] Step 2 : POS = 0 Step 3 : [ Find the smallest element in the array and its position] For I = 1 to N – 1 Do Step 4 : If ( A [ I ] < small ) Then Step 5 : small = A [ I ] Step 6 : POS = 1 [ End if ] [ End of step 3 for loop ] Step 7: [ Print the smallest and its position] Print “ smallest = “ , small , “ position = “ , pos Step 8: Exit
10) Explain linear search method with an algorithm.
Ans: Step 1 : START Step 2 : input N Step 3 : for I← 0 to N - Read A [ I ] Step 4 : Loc = - Step 5 : For I = 0 to N- 1 do Step 6 : If ( ele = A[I]) Then Step 7: Loc = I Step 8 : Goto step 9 [ end if ] [ end for ] Step 9 : If ( Loc > = 0 ) then Step 10: Print “ ele Found in location “ , Loc Step 11: else Step 12: Print “ ele not found ” Step 13 Stop
To print elements of an array a for loop is used. Ex: int a[10]; For(i=0;i<10;i++) Printf(“%d\n”,a[i]);
A two dimensional array can be printed as follows- Int a[3][4]; For(i=0;i<3;i++) { For(j=0;j<4;j++) { Printf(“%d\t”,a[i][j]); } Printf(“\n”); }
Question carrying one mark:-
A string is a sequence of one or more characters.
syntax: char arrayname [size]; Ex: char str [100];
A null character indicates the end of the string. A null string is a string with zero characters or no characters.
#include<string.h>
Which header file is needed to perform character operations? #include<ctype.h>
Write an example for string initialization. char str[100] ={“MYSORE CITY”};
What is the difference between gets() and scanf() function? gets() function receives a string input up to the end of the line or a new line character. This means the string may have blank spaces and punctuations. Scanf() function accepts a string only up to the first blank space or punctuation.
Question carrying 5 marks :-
(note:Write any 5 string operations with syntax and example)
Return_type_ specifier Function_name (type arg1, type arg2….) { local variable declarations; argument list statement1; statement2; … Body of the function statement n; return (expression); }
Return data type- indicates the data type of variable sent back from called function to calling function Function name- indicates the name of the function .It is an identifier Argument list- list of input variables and their datatypes received from calling function
Local variable declaration-list of data that required only for the function block in which they are declared. Body of the function - It includes declaration part (local variables) and a set of executable statements which will perform the required task. Return statement- indicates termination of function and transfer of control from called
function to calling function
Ex: int sum(int a,int b)
int c; c=a+b; return(c); }
Syntax: