M4.1-R3: 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. (1 x 10)
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. (1 x 10)
1.1 The following is a program
Main()
{
int x = 0;
while(x<=10)
for( ; ; )
if( ++ x%10 = =0)
break;
printf(“x = %d”, x);
}
What will be the output of the above program?
A) Will print x = 10
B) Will give compilation error
C) Will give runtime error
D) Will print x = 20
1.2 Consider the following variable declaration
Union x{
int i;
float f;
char c;
Main()
{
int x = 0;
while(x<=10)
for( ; ; )
if( ++ x%10 = =0)
break;
printf(“x = %d”, x);
}
What will be the output of the above program?
A) Will print x = 10
B) Will give compilation error
C) Will give runtime error
D) Will print x = 20
1.2 Consider the following variable declaration
Union x{
int i;
float f;
char c;
}y;
if the size of i, f and c are 2 bytes, 4 bytes and 1 byte respectively then the size of the variable y is:-
A) 1 byte
B) 2 bytes
C) 4 bytes
D) 7 bytes
if the size of i, f and c are 2 bytes, 4 bytes and 1 byte respectively then the size of the variable y is:-
A) 1 byte
B) 2 bytes
C) 4 bytes
D) 7 bytes
1.3 Pick up the odd one out from the following
A) x = x - 1
B) x - = 1
C) x - -
D) x = - 1
A) x = x - 1
B) x - = 1
C) x - -
D) x = - 1
1.4 What is the value of ‘average’ after the following program is executed?
main()
{
int sum, index;
float average;
sum = 0;
for( ; ; ) {
sum = sum + index; ++ index;
if (sum > = 100) break;
}
average = sum / index;
}
A) 91/13
B) 91/14
C) 105/14
D) 105/15
main()
{
int sum, index;
float average;
sum = 0;
for( ; ; ) {
sum = sum + index; ++ index;
if (sum > = 100) break;
}
average = sum / index;
}
A) 91/13
B) 91/14
C) 105/14
D) 105/15
1.5 Suppose i, j, k are integer variables with values 1, 2, 3 respectively. What is the value of
the following expression?
! (( j + k ) > (i + 5 ))
A) 6
B) 5
C) 1
D) 0
the following expression?
! (( j + k ) > (i + 5 ))
A) 6
B) 5
C) 1
D) 0
1.6 If a = -11 and b = -3. What is the value of a % b?
A) - 3
B) - 2
C) 2
D) 3
1.7 If c is a variable initialized to 1, how many times will the following loop be executed?
while(( c > 0 andand (c < 60))
{
c ++;
}
A) - 3
B) - 2
C) 2
D) 3
1.7 If c is a variable initialized to 1, how many times will the following loop be executed?
while(( c > 0 andand (c < 60))
{
c ++;
}
A) 61
B) 60
C) 59
D) 1
B) 60
C) 59
D) 1
1.8 Which one of the following describes correctly a static variable?
A) This cannot be initialized.
B) This is initialized once at the commencement of execution and cannot be changed at run
time.
C) This retains its value through the life of the program.
D) This is same as an automatic variable but is placed at the head of a program.
1.9 What will be the output of the following program?
main()
{
int a, *ptr, b, c;
a = 25;
ptr = anda;
b = a + 30;
c = *ptr;
printf(“%d %d %d”, a, b, c);
}
A) 25, 25, 25
B) 25, 55, 25
C) 25, 55, 25
D) None of the above
1.10If a = 0·aa and b = a << 1 then which of the following is true
A) b = a
B) b = 2a
C) a = 2b
D) b = a - 1
A) This cannot be initialized.
B) This is initialized once at the commencement of execution and cannot be changed at run
time.
C) This retains its value through the life of the program.
D) This is same as an automatic variable but is placed at the head of a program.
1.9 What will be the output of the following program?
main()
{
int a, *ptr, b, c;
a = 25;
ptr = anda;
b = a + 30;
c = *ptr;
printf(“%d %d %d”, a, b, c);
}
A) 25, 25, 25
B) 25, 55, 25
C) 25, 55, 25
D) None of the above
1.10If a = 0·aa and b = a << 1 then which of the following is true
A) b = a
B) b = 2a
C) a = 2b
D) b = a - 1
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. (1 x 10)
2.1 It is not possible to print the % character as the function printf treats % as the beginning
of a conversion specification.
2.2 A structure can include one or more pointers as members.
2.3 It is not possible to have formatted input / output in ‘C’.
2.4 It is not possible to have nested if - else statements in ‘C’.
2.5 The increment operator ++ does not work with float variable.
2.6 *a is the same as a[ ] in a parameter declaration.
2.7 In ‘C’ programming language, strings are represented using an array.
2.8 Relational operators have higher precedence than arithmetic operators.
2.9 A structure cannot be a member of a union.
2.10*p++ increments the content of the location pointed by p.
and ENTER in the “tear-off” sheet attached to the question paper, following
instructions therein. (1 x 10)
2.1 It is not possible to print the % character as the function printf treats % as the beginning
of a conversion specification.
2.2 A structure can include one or more pointers as members.
2.3 It is not possible to have formatted input / output in ‘C’.
2.4 It is not possible to have nested if - else statements in ‘C’.
2.5 The increment operator ++ does not work with float variable.
2.6 *a is the same as a[ ] in a parameter declaration.
2.7 In ‘C’ programming language, strings are represented using an array.
2.8 Relational operators have higher precedence than arithmetic operators.
2.9 A structure cannot be a member of a union.
2.10*p++ increments the content of the location pointed by p.
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. (1 x 10)
word(s)/phrase(s) in column Y. Enter your selection in the “tear-off” answer sheet
attached to the question paper, following instructions therein. (1 x 10)
X Y
3.1 An Operator in ‘C’ permits two different expressions to A. The operator andand
appear in situations where only one expression is ordinarily be used.
3.2 Variables, internal to a function, come into existence B. Static variables
when the function is called
3.3 No space allocated for storage of character during C. Global variables
compilation time
3.4 p is pointer to a function that returns a pointer to D. The comma operator (,)
integer
3.5 Self-referencing structure E. int *p[10]
3.6 Accomplishing indirection with pointer to structure F. automatic variable
3.7 Random access in the file; file specified through file G. Useful for link-list
descriptor implementation
3.8 Returns initialized storage in run-time H. seek
3.9 Variables can be defined in ‘C’ which occupies less I. fseek
space than character variables
3.10 Valid mode for opening a file; permits read and write J. calloc
K. w+
L. malloc
M. r+
N. bit-fields
O. arrow operator
P. int(*(*pc))
Q. char *s
3.1 An Operator in ‘C’ permits two different expressions to A. The operator andand
appear in situations where only one expression is ordinarily be used.
3.2 Variables, internal to a function, come into existence B. Static variables
when the function is called
3.3 No space allocated for storage of character during C. Global variables
compilation time
3.4 p is pointer to a function that returns a pointer to D. The comma operator (,)
integer
3.5 Self-referencing structure E. int *p[10]
3.6 Accomplishing indirection with pointer to structure F. automatic variable
3.7 Random access in the file; file specified through file G. Useful for link-list
descriptor implementation
3.8 Returns initialized storage in run-time H. seek
3.9 Variables can be defined in ‘C’ which occupies less I. fseek
space than character variables
3.10 Valid mode for opening a file; permits read and write J. calloc
K. w+
L. malloc
M. r+
N. bit-fields
O. arrow operator
P. int(*(*pc))
Q. char *s
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. (1 x 10)
the list below. Enter your choice in the “tear-off” answer sheet attached to the
question paper, following instructions therein. (1 x 10)
A. Change B. trinary C. - operator
D. Automatic E. Variable F. “and” operator
G. Static H. Dynamically I. Externally
J. void K. A character L. An integer
M. EOF N. fclose O. True
D. Automatic E. Variable F. “and” operator
G. Static H. Dynamically I. Externally
J. void K. A character L. An integer
M. EOF N. fclose O. True
4.1 printf( ) function uses _________ number of arguments.
4.2 ________ can be used as both binary and unary operators.
4.3 Link lists can be created _____________.
4.4 Loop invariants are assertions that remain _______ before and after execution of loops.
4.5 File descriptor is ______________.
4.6 Pointer arguments enable a function to access and _____ objects defined in the calling
routine.
4.7 The function getchar( ) returns _______ when there is no more input character.
4.8 Any pointer can be cast to __________ without loss of information.
4.9 To prevent the use of functions across different files, ____ storage class is used.
4.10 ? : is ________ operator.
PART TWO
(Answer any FOUR questions)
5.
a) Discuss with the help of examples the action of break statement and the continue statement.
b) Does the null statement have any uses besides indication that the body of a loop is empty?
Explain.
c) What is the purpose of the \? Escape sequence?
(8+4+3)
6.
a) Is it legal to put a function declaration inside the body of another function? If yes, give an
example.
b) Is it legal for a function f1 to call f2, which then calls f1? Justify your answer.
c) Write a ‘C’ function that returns the k-th digit from the right in the positive integer n. For
example, digit(829,1) returns 9, digit(829,3) returns 8. If k is greater than the number of
digits in n then the function is to return -1. Include appropriate documentation in your
program.
(4+2+9)
7.
a) If a pointer is an address, what does the expression like p + j mean?
b) Is i[a] same as a[i]? Justify your answer.
c) Write the following function:
Bool search(int a[], int n, int x);
Where a is an array to be searched, n is the number of elements in the array, and x is
the search key. “search” should return TRUE if x matches some element of a, FALSE if it
doesn’t. Use pointer arithmetic to visit array elements. Include appropriate
documentation in your program.
(4+2+9)
8.
a) Develop an algorithm to do the following:
Read an array of 20 elements and then send all negative elements of the array to the
end without altering the original sequence.
b) Draw a flow chart and then write a ‘C’ program to generate first 15 members of the following
sequence.
1, 3, 4, 7, 11, 18, 29, …
(5+10)
9. Develop a flowchart and then write a program for analyzing a line of text stored in a file
by examining each of the characters and displaying into which of several different categories vowels, constants, digits, white spaces it falls. Count of the number of vowels, consonants, digits and white space characters. Include an appropriate documentation in your program.
4.2 ________ can be used as both binary and unary operators.
4.3 Link lists can be created _____________.
4.4 Loop invariants are assertions that remain _______ before and after execution of loops.
4.5 File descriptor is ______________.
4.6 Pointer arguments enable a function to access and _____ objects defined in the calling
routine.
4.7 The function getchar( ) returns _______ when there is no more input character.
4.8 Any pointer can be cast to __________ without loss of information.
4.9 To prevent the use of functions across different files, ____ storage class is used.
4.10 ? : is ________ operator.
PART TWO
(Answer any FOUR questions)
5.
a) Discuss with the help of examples the action of break statement and the continue statement.
b) Does the null statement have any uses besides indication that the body of a loop is empty?
Explain.
c) What is the purpose of the \? Escape sequence?
(8+4+3)
6.
a) Is it legal to put a function declaration inside the body of another function? If yes, give an
example.
b) Is it legal for a function f1 to call f2, which then calls f1? Justify your answer.
c) Write a ‘C’ function that returns the k-th digit from the right in the positive integer n. For
example, digit(829,1) returns 9, digit(829,3) returns 8. If k is greater than the number of
digits in n then the function is to return -1. Include appropriate documentation in your
program.
(4+2+9)
7.
a) If a pointer is an address, what does the expression like p + j mean?
b) Is i[a] same as a[i]? Justify your answer.
c) Write the following function:
Bool search(int a[], int n, int x);
Where a is an array to be searched, n is the number of elements in the array, and x is
the search key. “search” should return TRUE if x matches some element of a, FALSE if it
doesn’t. Use pointer arithmetic to visit array elements. Include appropriate
documentation in your program.
(4+2+9)
8.
a) Develop an algorithm to do the following:
Read an array of 20 elements and then send all negative elements of the array to the
end without altering the original sequence.
b) Draw a flow chart and then write a ‘C’ program to generate first 15 members of the following
sequence.
1, 3, 4, 7, 11, 18, 29, …
(5+10)
9. Develop a flowchart and then write a program for analyzing a line of text stored in a file
by examining each of the characters and displaying into which of several different categories vowels, constants, digits, white spaces it falls. Count of the number of vowels, consonants, digits and white space characters. Include an appropriate documentation in your program.
No comments:
Post a Comment