Tuesday, 12 July 2016

January 2013 M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH ‘C’ LANGUAGE

 January, 2013
M3-R4: PROGRAMMING AND PROBLEM SOLVING THROUGH ‘C’ LANGUAGE

NOTE:
1. There are TWO PARTS in this Module/Paper. PART ONE contains FOUR questions and PART TWO contains FIVE questions.
2. PART ONE is to be answered in the TEAR-OFF ANSWER SHEET only, attached to the
question paper, as per the instructions contained therein. PART ONE is NOT to be answered in
the answer book.
3. Maximum time allotted for PART ONE is ONE HOUR. Answer book for PART TWO will be
supplied at the table when the answer sheet for PART ONE is returned. However, candidates,
who complete PART ONE earlier than one hour, can collect the answer book for PART TWO
immediately after handing over the answer sheet for PART ONE.

TOTAL TIME: 3 HOURS TOTAL MARKS: 100
(PART ONE – 40; PART TWO – 60)


PART ONE
(Answer all the questions)

1. Each question below gives a multiple choice of answers. Choose the most appropriate one and enter in the “tear-off” answer sheet attached to the question paper, following instructions therein. (1x10)

1.1 If a=8, b=3 and c=-5 are integers, then value of a*b/c is
A) -4
B) -2.8
C) +2.8
D) +3



1.2 Which of the following is a valid identifier?
A) 1return
B) return1
C) return
D) $return_1

1.3 Which of the following is a valid string constant?
A) “programming”
B) “programming
C) ‘programming
D) $ programming $

1.4 How will you free the allocated memory?
A) remove(var-name);
B) free(var-name);
C) delete(var-name);
D) dalloc(var-name);

1.5 If i = 8 and j = 5 are two integers, then the value of (i>0) || (j < 5) is
A) -5
B) 1
C) 0
D) +5

1.6 How many times "INDIA" will get printed?
#include<stdio.h>
int main()
{
int x;
for(x=-1; x<=10; x++)
{
if(x < 5)
continue;
else
break;
printf("INDIA");
}
return 0;
}
A) Infinite times
B) 11 times
C) 0 times
D) 10 times

1.7 A group of related data that share a common name is
A) Pointer
B) Array
C) Function
D) None of the above

1.8 In ‘C’, if you pass an array as an argument to a function, what actually gets passed?
A) Value of elements in array
B) First element of the array
C) Base address of the array
D) Address of the last element of array

1.9 What does fp point to in the program?
#include<stdio.h>
int main()
{
FILE *fp;
fp=fopen("trial", "r");
return 0;
}
A) The first character in the file
B) A structure which contains a char pointer which points to the first character of a file
C) The name of the file
D) The last character in the file

1.10 Which of the following language is predecessor to ‘C’ Programming Language?
A) A
B) B
C) ADA
D) C++


2. Each statement below is either TRUE or FALSE. Choose the most appropriate one and ENTER in the “tear-off” sheet attached to the question paper, following instructions therein. (1x10)

2.1 Sizes of short integer and long integer would vary from one platform to another.
2.2 A structure can contain similar or dissimilar elements.
2.3 Names of functions in two different files linked together must be unique.
2.4 Functions that do not contain return statement do not return any value.
2.5 malloc() allocates memory from the heap and not from the stack.
2.6 Every ‘if’ statement must also include ‘else’.
2.7 The three declarations char **apple, char *apple[], and char apple[][] are same.
2.8 malloc() returns a float pointer if memory is allocated for storing float's and a double pointer if
memory is allocated for storing double's.
2.9 If we have to execute the program with different set of inputs, we need to recompile the program
each time.
2.10 Compiler translates the of source code into object code before the program can be executed.

3. Match words and phrases in column X with the closest related meaning/word(s)/phrase(s) in column Y. Enter your selection in the “tear-off” answer sheet attached to the question paper, following instructions therein. (1x10)

                                   X                                                      Y

3.1 Used when we want to test more                         A. menu selection
than one condition and make
decision
3.2 Size of float and double in bytes                         B. logical operators
3.3 A linked list is a                                                  C. stdio.h
3.4 The switch statement is often used for               D. stdlib.h
3.5 Input/output function prototypes and                 E. 4,8
macros are defined in
3.6 Gives the current position in the file                 F. integer value
3.7 Header file should be included to use               G. strcat()
 malloc() function
3.8 A piece of information passed to                      H. dynamic data structure
 a method
3.9 By default functions return                               I. strcmp()
3.10 To concatenate two strings we use                 J. argument
                                                                               K. ftell()
                                                                                L. pointer
                                                                              M. linked list

4. Each statement below has a blank space to fit one of the word(s) or phrase(s) in the list below. Enter your choice in the “tear-off” answer sheet attached to the question paper, following instructions therein. (1x10)

A. header                          B. garbage                            C. alloc
D. goto                              E. void                                 F. double quotes
G. Flowchart                    H. deallocate                         I. return
J. logical                          K. 1972                                  L. ->
M. conditional

4.1 ________ breaks the normal sequential execution of the program.
4.2 Character constants should be enclosed between ________.
4.3 The operator && is an example for ________ operator.
4.4 Pictorial representation of an algorithm is ________.
4.5 A pointer contains ________ until it is initialized.
4.6 If a function return type is declared as ________ it cannot return any value.
4.7 The ________ operator can be used to access structures elements using a pointer to structure
variable only.
4.8 The keyword used to transfer control from a function back to the calling function is ________.
4.9 NULL macro is defined in ________ file.
4.10 ________ function is used to request memory space.

PART TWO
(Answer any FOUR questions)


5.
a) What is the difference between linear search and binary search?
b) Write a ‘C’ program to find out sum of diagonal elements of a matrix using ‘C’.
c) Distinguish between compiler error and runtime error with the help of an example.
(5+6+4)

6.
a) Write a ‘C’ program to copy data of one file to another file.
b) What is the scope of global, local and register variables.
c) What is a preprocessor and what are the advantages of preprocessor? What are the facilities
provided by preprocessor?
(9+3+3)

7.
a) What is the difference between array and linked list? Discuss the advantage of linked list over
arrays.
b) Write a program to create a link list. There should be 10 nodes in the list, each node contains
an integer between 1 – 10. The list should be printed at the end.
(5+10)

8.
a) Differentiate between do-while loop and while loop with the help of one example for each.
b) What is the purpose of using functions in ‘C’ programming? Differentiate declaration and
definition of a function.
c) How will you pass parameters to a function? Briefly describe two mechanisms of parameter
passing in ‘C’ language.
(6+4+5)

9.
a) Write a ‘C’ Program to create a file of numbers and copy odd number into second file and even
number into third file.
b) Write a ‘C’ program to find out a factorial of a given number?
(8+7)