Pages

Thursday, 14 July 2016

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

January, 2011
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 ‘C’ Programming Language was developed and written by
A) Martin Richards
B) Dennis Ritchie
C) Ken Thompson
D) Herman Hellorith
Answer 

1.2 Which of the following is false in ‘C’ Programming Language
A) Keywords can be used as variable names
B) Variable names can contain digits
C) Variable names do not contain blank spaces
D) Capital letters can be used in variable names.
Answer 

1.3 What will be the output of the following ‘C’ program
main()
{
int a=5;
float b=5.0;
if(a==b)
printf(“a and b are equal”);
else
printf(“a and b are different”);
}
A) a and b are equal
B) a and b are different
C) Error
D) None of the above
Answer 

1.4 What will be the output of the following ‘C’ program?
main()
{
int a=1;
int b=5;
if(a=5||b>10)
printf(“I will certainly pass”);
else
printf(“I am not so sure about the result”);
}
A) I will certainly pass
B) I am not so sure about the result
C) Error
D) None of the above
Answer 

1.5 What will be the output of the following program?
main()
{
int a;
printf(“%d”,a);
}
A) 0
B) 1
C) Error
D) Unpredictable Value
Answer 

1.6 A ‘C’ expression contains relational, assignment and arithmetic operators. There are no
parentheses used. They will be evaluated in which of the following order
A) Assignment Relational Arithmetic
B) Arithmetic Relational Assignment
C) Relational Arithmetic Assignment
D) Assignment Arithmetic Relational
Answer 

1.7 Prototype of function named ‘fun’ is: int fun(int a, float b) Which of the following is
true about function ‘fun’:
A) It takes two inputs, one integer type and the other float type but returns nothing
B) It takes two inputs, one integer type and the other float type but returns 0
C) It takes two inputs, one integer type and the other float type but returns an integer
D) It takes two inputs, one integer type and the other integer type but returns float
Answer 

1.8 What will happen if an element is assigned a value to an element of an array whose
subscript exceeds the size of the array
A) It will not be allowed, but no error message will be generated
B) Compiler will generate an error message suggesting the same
C) The element will be assigned NULL VALUE.
D) Some other data may be overwritten
Answer 

1.9 In the following ‘C’ code
{
FILE *f = fopen( fileName, "r");
fread(f);
if(????)
puts(“End of file reached”);
}
Which one of the following can replace the ???? in the code above to determine if the end of
a file has been reached?
A) f == EOF
B) feof( f )
C) eof( f )
D) f == NULL
Answer 

1.10 With every use of a memory allocation function, what function should be used to release
allocated memory which is no longer needed?
A) unalloc()
B) Dropmem()
C) Dealloc()
D) free()
Answer 

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 A structure can contain pointer to itself.
2.2 Size of all elements in a union should be same.
2.3 Size of a pointer is equal to the data type it points to.
2.4 In ‘C’, the compiler does not check if the subscript used for an array exceeds size of the
array.
2.5 A ‘for’ loop in ‘C’ has three statements, namely, assignment, test and increment statements.
2.6 cout and cin can be used for output and input respectively in ‘C’ language.
2.7 The default initial value of a static int variable is zero.
2.8 Binary search can be easily performed on a linked list.
2.9 A function name can be passed as an argument to another function.
2.10 A ‘C’ function can contain many return statements.

Answer 


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 Do-while loop is                                                 A. Directives
3.2 This loop control structure takes                        B. You cannot find its address
 you to the beginning of the loop
3.3 This is a mandatory function in                         C. To clear the specified buffer
every ‘C’ program. Execution starts
 from this function
3.4 Value of static storage variable                          D. continue
3.5 Preprocessor commands are also                       E. The same data types placed in
 known as contiguous memory locations
3.6 An array is a collection of                                  F. Persists between different function
                                                                                      calls
3.7 The condition that a linked list is empty           G. Case control structure
3.8 If ‘x’ is a variable of storage class register        H. Executed at least once
3.9 If you have to use many if-else conditions,       I. Will be there if start== is true.
they can be usually implemented by
3.10 The purpose of library function fflush() is       J. main().
                                                                                  K. array
                                                                                  L. *
                                                                                 M. break

Answer 



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. \b                                      B. alloc.h                              C. 1 byte
D. stdio.h                              E. CPU Registers                  F. &&
G. fclose()                             H. 65                                     I. An Error
J. Array of characters            K. \a                                     L. &
M. ==

4.1 Logical AND operator is denoted by ________.
4.2 Size of char data type is ________.
4.3 The variables of storage class register are stored in ________.
4.4 If you try to multiply or add two pointers, it will result in ________.
4.5 In ‘C’, strings are stored in the form of ________.
4.6 Escape sequence for backspace is ________.
4.7 Function used to close a file is _________.
4.8 The header file which must be included, if you want to use malloc() or calloc() is
________.
4.9 The macro FILE is defined in header file ________.
4.10 The ASCII value, in decimal, of character ‘A’ is ________.

Answer 


PART TWO
(Answer any FOUR questions)

5.
a) Explain the concept of structured programming in detail.
b) List out the rules to declare a valid variable in ‘C’ program. Evaluate the following expression and show the hierarchy of operations:
( 2 + 4 ) / 3 + 2%3 * 2 – 5
c) Define a structure Time having integer data members hour, minute, second. Write a
program to enter two variables of the type Time and then add these two variables and store
the result into third variable. Also validate the second and minute of the result and print it.
(5+5+5)

6. A, B and C are three 3x3 matrices containing real elements.
a) Write a ‘C’ function to input from user appropriate values into matrices A and B. Use
suitable loops. Make use of pointers if necessary.
b) Write a ‘C’ function to calculate matrix C such that C=A+B Use suitable loops. Make use of pointers if necessary
c) Write a ‘C’ program to call the above two functions and print Matrix C suitably. Write suitable
prototype etc. Use suitable loops. Make use of pointers if necessary
(5+5+5)

7.
a) Write and explain the action of WHILE statement. Develop a program in ‘C’ language to
compute the average of every third integer number lying between 1 and 100. Include
appropriate documentation.
b) Develop a function to calculate sum of n even integers starting from a given even integer.
c) Identify all the compound statements which appear in the following program segment:
{
sum=0;
do{
scanf(“%d”, &i);
if (i < 0)
{
i=-i;
++flag;
}
sum += i;
} while (i != 0);
}
(5+5+5)

8.
a) Write a ‘C’ program to find the minimum of the 8 floating point numbers and its place in the
array.
b) Write an interactive ‘C’ program to evaluate the series: 1 – 1/2 + 1/3 – 1/4 …±1/n, where n is
entered from keyboard.
c) Write a ‘C’ program to calculate the electricity bill using if..elseif, as per the following
details
* Given the number of units consumed, unit charges are as follows:
i) For first 50 units Rs. 0.50/unit
ii) For next 100 units Rs. 0.75/unit
iii) For next 100 units Rs. 1.20/unit
iv) For unit above 250 Rs. 1.50/unit
* Add fuel surcharge 20% and Govt. Tax 10% on bill to calculate the total bill.
(5+5+5)

9.
a) Write a suitable ‘C’ program to print the following structure.
*
**
***
****
*****
******
the number of rows should be input from the user.

b) Write a program to input a 3x3 matrix and to print its transpose.
c) Consider outline of ‘C’ program given below:
#Include suitable header files
void main()
{
suitable prototype of function interchange()
int a=10, b=20;
interchange(&a,&b);
printf(“a=%d b=%d”,a,b)
}
The function interchange() interchanges the values of the variables supplied to it. So the
output of the program is
a=20 b=10
Write suitable interchange() function. Also fill in the gaps of this program so that it
produces the desired output.
(5+5+5)

Next Set

1 comment: