Académique Documents
Professionnel Documents
Culture Documents
1 Introduction to computers
2011 Q1(viii) A do-while loop is useful when we want that statement within a loop must be
executed (a) only once.
[Hint: A do-while loop allows codes / statements to be executed once based on a given condition. E.g.
Do B
While (A = TRUE)
End While ]
Hints
i starts from 1 upto 5 with an increment of 1 (i.e. i=i+1)
The value of (i % 2) = the remainder after dividing i by 2
If i is even then (i%2 ) = 0
If i is odd then (i%2) = 1
If (i%2) is 1 (i.e. true) then Continue the loop without
executing Printf(%d,i)
If (i%2) is 0 (i.e. false) then Printf(%d,i)
Therefore the final result is if i is odd then dont print.
If i is even then print i. Therefore the answer will be
2,4.
2011 Q1(x) Which of the following is an external command in DOS? Ans. (a) Edit.
[Hint: See Chapter 1.4: Basic concepts of operating systems/p2-3 ]
2011 Q4. Write a C program to input a number and calculate the sum of individual digits present in
that number and also print the number in reverse order.
Example: Input 123
Output Sum of individual digits: 6
Reverse of the number: 321.
Solution:
#include<stdio.h>
#include<conio.h>
void main( )
{
clrscr( );
int num, remainder=1, quotient, sum=0, rev=0;
printf("Enter the number");
scanf("%d",&num);
while (num != 0)
//Till num is not equal to 0
{
remainder = num % 10;
//num%10 is the remainder e.g. 123%10 = 3
sum = sum + remainder;
// sum = 0 + 3
rev = rev * 10 + remainder;
//create the reverse number
quotient = num/10;
//num/10 is the quotient, e.g. 123/10=12
num = quotient;
//put the value of quotient into num, i.e. num=12
}
print("Sum of the digits:%d",sum);
printf("\nThe reverse of the number:", rev);
getch( );
//Wait for a keyboard action to come out from the DOS screen
}
2011 Q7(a) What is an array? How to initialize an array?
Ans: See Chapter 1.5: Introduction to computer language p20-21.
Example:
#include <stdio.h>
#include<conio.h>
int g;
int add(int x, int y);
void main ( ) {
int a = 10, b = 20;
g = add(a, b);
printf(%d, g);
getch();
}
add (int m, int n) {
int s;
s = m + n;
return (s);
}
2011 Q8(a)What is the difference between automatic and register storage class? Discuss
when they are used. [5]
Ans.
Storage
Class
Automatic
Register
Where the
variable is
stored
Memory
(RAM)
CPU
Registers
Initial value
of the
variable
Default value
is garbage
value
Default value
is garbage
value
Scope of the
variable
When it is used
Local to the
block
Local to the
block
2011 Q8(c)What is the difference between interpreter and compiler? What are local variable
and global variable? Explain with example. [5]
Ans: Difference between interpreter and compiler
Compiler and interpreter are programs that run the instructions written in a certain programming
language and convert them into the machine code that a computer can understand.
Compiler
More time is required for analyzing and processing
of the program.
The resulting code of the compiler is in the form of
machine code or binary format.
In case of compiler, the resulting code is executed by
the computer hardware.
The execution of the program is fast in the compiler.
Examples: C, ForTran, PASCAL, etc.
Interpreter
Lesser time is required for analyzing and processing
of the program.
The resulting code is in the form of the intermediate
code.
In an interpreter; another program interprets the
resulting code.
The program execution speed is comparatively low.
BASIC is an interpreter.
Ans:
Local variable
A local variable is a variable which is either a variable declared within the function or is an
argument passed to a function. If we declare variables in a function then we can only use them
within that function.
Global variable
A global variable is a variable which is accessible in multiple scopes. It is important to note that
global variables are only accessible after they have been declared. Global variables can be seen
from all functions.
#include <stdio.h>
#include <conio.h>
int g;
//int x and int y are defined within the function add( ) so they are
void main( ) {
clrscr( );
int a, b, c;
//a, b, c are local variables
a = 1;
b = 2;
c = a + b;
printf(%d", c);
//The display will be 3
getch( );
}
2011 Q9(a) What do you mean by an operating system? What are the advantages of an UNIX
operating system? [7]
Ans. See note of Chapter 1.4 for the first question.
Advantages of UNIX operating system
1. Full multitasking with protected memory: Multiple users can run multiple programs each at
the same time without interfering with each other or crashing the system.
2. Very efficient virtual memory: Many programs can run with a modest amount of physical
memory.
3. Access controls and security: All users must be authenticated by a valid account and
password to use the system. All files are owned by particular accounts. The owner can
decide whether others have read or write access to his files.
4. A rich set of small commands and utilities that do specific tasks well -- not cluttered up with
lots of special options.
5. Ability to string commands and utilities together in unlimited ways to accomplish more
complicated tasks -- not limited to preconfigured combinations or menus, as in personal
computer systems.
6. A powerfully unified file system. Everything is a file: data, programs, and all physical
devices. Entire file system appears as a single large tree of nested directories, regardless of
how many different physical devices (disks) are included.
7. A lean kernel that does the basics for you but doesn't get in the way when you try to do the
unusual.
8. Available on a wide variety of machines - the most truly portable operating system.
9. Optimized for program development, and thus for the unusual circumstances that are the
rule in research.
6
2011 Q9(b) What is virtual memory? What are its advantages? [5]
Virtual memory is a feature of an operating system that enables a process to use a memory (RAM)
address space that is independent of other processes running in the same system
If a computer lacks the random access memory (RAM) needed to run a program or operation, OS
uses virtual memory to compensate.
Virtual memory combines the computers RAM with temporary space on the hard disk. When
RAM runs low, virtual memory moves data from RAM to a space called a paging file. Moving data
to and from the paging file frees up RAM to complete its work. The more RAM a computer has, the
faster the programs will generally run.
2011 Q9(c) Explain the difference between shell and kernel. [3]
Both shell and kernel are parts of an operating system. These both parts are used for performing
any operation on the system.
When a user gives a command for performing any operation, the request first goes to the Shell
part of the OS. It translates the Human Program into the Machine Language. Then the request in
the form of machine language will be transferred to the kernel (another sets of programs).
Therefore shell is called just an interpreter.
Kernal is the heart of an Operating System. When the kernel receives a request (in machine
language) from the Shell it will process the request and output the result by printer, or monitor,
etc.
Application Programs Shell of OS Kernel of OS
2011 Q11(a) Write a program in C to calculate the value of the series. [5]
1+1/(1+2) + 1/(1+2+3) + ..+ 1/(1+2+3++N)
#include<stdio.h>
#include<conio.h>
void main( ){
clrscr( );
int i, N, sum=0, totsum=0;
printf(Put N:);
scanf(%d, &N);
2011 Q11(b) Define algorithm. Explain with example. Mention the five important peoperties
of an algorithm. [5]
The abbreviated statements in English (or in other natural language) that specify the steps to be
performed in solving the problem are called the program design language (PDL) statements or
pseudocode.
The finite set of PDL statements, which describe the logic for solving a specific problem, is
called an algorithm and the process of defining PDL statemtns is called the algorithm
development.
An algorithm has five notable features:
1.
2.
3.
4.
5.
Algorithm of Problem
1. Input X1, X2, X3.
2. Compare X1 with X2.
3. If X1 is larger than X2, compare X1 with X3.
If X1 is larger than X3, report X1 as the largest;
Otherwise, report X3 as the largest.
4. If X1 is not larger than X2, compare X2 with X3.
If X2 is larger than X3, report X2 as the largest;
Otherwise, report X3 as the largest.
5. End
2011 Q11(c) Write a menu driven program using function (call by reference) to find the
following. [5]
(i) Factorial
(ii) Odd / Even
(iii) Prime
#include<stdio.h>
#include<conio.h>
void factorial( );
void evenodd( );
void prime( );
void main( ){
//The main function holding the menu
clrscr( );
int i, option;
printf(MENU);
printf(1. Determine the factorial\n);
printf(2. Determine number whether it is odd or even\n);
printf(3. Check whether a number prime number\n);
printf(Type the number: );
scanf(%d, &option);
8
switch (option) {
case 1:
factorial( ); break;
case 2:
oddeven( ); break;
case 3:
prime( ); break;
default:
menu( ); break;
}
//switch ends here
//main function ends here
void factorial( ){
int N, prod=1;
printf(Enter a number to calculate its factorial);
scanf(%d, N);
for (i=1; i<=N; i++){
prod = prod * i;
}
//for loop ends here
printf (\nFactorial(%d) = %d, N, prod );
}//factorial function ends here
//display: Factorial(5)=120
void evenodd( ){
int N;
prinf(Enter a number: );
scanf(%d, N)
if (N%2 = = 0){
//no remainder, i.e. even number
printf(%d is an even number, N);
}
else
{
printf(%d is an odd number, N);
}
//function evenodd( ) ends here
void prime( ){
int n, i, result = 1;
//result = 1 means n is a prime number
printf(Enter a number\n);
scanf(%d, &n);
for (i=2; i <= n 1; i++){
if(n%i = = 0){
result = 0;
break;
}
}
if (result = = 1){
//if result = =1 then n is a prime number
printf(%d is a prime number, n);
}
else {
//otherwise the number n is prime
printf(%d is a not a prime number, n);
}
//function prime( ) ends here
Question Paper of 2012
(b) *
(c) /
(d) %
Ans. (d) %
[Hint: % is an operand to calculate the remainder of two integers e.g. 7%4 = 3; dividing 7 by 4 produces a
remainder of 3 ]
Q1(ii) C is a language
(a) procedural (b) object-oriented
Ans. (a) procedural
[Hint: Just memorize it, otherwise we shall require to know the Object Oriented Programming. C++ is an
Objected Oriented Programming language ]
(c) 12 bits
(d) 16 bits
(d) 0101
(c) 011101111001
(d) 101110111001
10
11