1. ASSIGNMENT BOOKLET
M.Sc.(Mathematics with Applications in Computer Science)
Programming and Data Structures
(Valid from 1st
January, 2014 to 30th
November, 2014)
School of Sciences
Indira Gandhi National Open University
Maidan Garhi,
New Delhi-110068
(For January, 2014 cycle)
MMT-001
It is compulsory to submit the assignment before filling
in the exam form.
2. 2
Dear Student,
Please read the section on assignments in the Programme Guide for Elective courses that we sent you
after your enrolment. A weightage of 20%, as you are aware, has been earmarked for continuous
evaluation, which would consist of one tutor-marked assignment for this course. The assignment is in
this booklet.
Instructions for Formating Your Assignments
Before attempting the assignment please read the following instructions carefully.
1) On top of the first page of your answer sheet, please write the details exactly in the following format:
ROLL NO :……………………………………………
NAME :……………………………………………
ADDRESS :……………………………………………
……………………………………………
……………………………………………
COURSE CODE: …………………………….
COURSE TITLE : …………………………….
ASSIGNMENT NO.: ………………………….…
STUDY CENTRE: ………………………..….. DATE: ……………………….………………...
PLEASE FOLLOW THE ABOVE FORMAT STRICTLY TO FACILITATE EVALUATION AND
TO AVOID DELAY.
2) Use only foolscap size writing paper (but not of very thin variety) for writing your answers.
3) Leave 4 cm margin on the left, top and bottom of your answer sheet.
4) Your answers should be precise.
5) This assignment is to be submitted to the Study Centre as per the schedule made by the study centre.
Answer sheets received after the due date shall not be accepted.
We strongly suggest that you retain a copy of your answer sheets.
6) This assignment is valid only upto November, 2014. If you have failed in this assignment or fail to
submit it by November, 2014, then you need to get the assignment for the year 2015 and submit it as
per the instructions given in the programme guide.
7) You cannot fill the exam form for this course till you have submitted this assignment. So solve it
and submit it to your study centre at the earliest.
We wish you good luck.
3. 3
Assignment
(To be done after studying the course material)
Course Code: MMT-001
Assignment Code: MMT-001/TMA/2014
Maximum Marks: 100
1. a) Debug the following C program:
#includ <stdio.h>;
int main()
{ int a, int b, int c;
printf(“a, b, c are integer variablesn”).
{ a =5; b=6; c=7;
printf(“The values of a, b and c are:” a, b, c);
printf(“na, b and c are consecutive integers.”);
return 0;
}
What will the output be after correcting the errors? [3]
b) Write C statements that show the use of the escape sequences n and t. [2]
c) The formula for converting the temperature from Fahrenheit to Celsius is
( )
Write a C program that implements this formula. Check your program for different
values of fahrenheit. [2]
d) Which of the following are valid C identifiers? [4]
(i) Sah_Rukh_Khan (ii) 01matrix
(iii) target_value (iv) etypedef
(v) L.C.M. (vi) A/c_balance
(vii) +ve_numbers (viii) _underscore
e) Evaluate the following expressions stepwise such that in each step only one operator
should be evaluated. [4]
(i)
(ii) ( ) ( )
(iii) ( ) ( )
(iv)
2. a) What error does the compiler show when the you run the following program? Explain
why this error occurs. How can you remove this error? [3]
#include <stdio.h>
int main()
{ int x=5, y,z;
y=---x;
printf("%d", y);
return 0;
}
4. 4
b) Recall that the volume of a cylinder with radius and height is given by the
following formula:
Write a C program that calculates the volume of a cylinder using the above formula
and prints the result in right justified floating point format with width and having
digits after the decimal. [3]
c) If , , and are variables of type int having values , , and respectively,
what are the values of the following expressions? Justify your answers. [4]
(i) ( ) ( ) (ii)
(iii) (iv)
d) Write a C program that asks the user to enter a 4 digits number. If the number
entered by the user is matched with a specified number, then the program terminates
after displaying the message “Good Luck! You Succeed.” Otherwise it keeps asking
the user to enter a number upto wrong attempts. After wrong attempts the
program terminates with the message “Bad Luck? Try Again Next Time.” [3]
e) Look at the program 4.5 at Page No. 86 of Block 1 of your study material.
Do the following modifications:
(i) Replace the condition with in first if statement.
(ii) Replace the condition with in the second if statement.
(iii) Replace the condition by in the third if statement.
What will the output of the program be now? [2]
3. a) Explain the use of ternary if()- then- else operator with the help of an example. [3]
b) What does the following program calculates? Explain step by step the procedure. [4]
#include <stdio.h>
int main ()
{ int u, v, temp;
printf ("Please type in two nonnegative integers.n");
scanf ("%d%d", &u, &v);
while ( v != 0 )
{ temp = u % v;
u = v;
v = temp;
}
printf ("%dn", u);
return 0;
}
c) Using a simple example explain the difference between a pointer and an ordinary
variable. [3]
5. 5
d) Write a C program to print the following: [6]
[Hint: Analyze the above figure before writing the program. First think how you can
print the slash’s and backslash’s. Then observe the pattern in each row.]
e) Define two integer arrays, each 10 elements long, called "array1" and "array2".
Using a loop, put some kind of data in each and add them term by term into another
10 element array named "arrays_sum".
Finally print all results in a table with an index number as given below. [4]
Sum of Two Integer Arrays
1. 2+10 = 12
2. 4+20 = 24
3. 6+30 = 36
….. etc.
4. a) Write a function named next_alphabet(…) that takes an English alphabet and
returns the next alphabet. If the alphabet is passed to the function then it should
return the alphabet . [3]
b) Write a C program to calculate the average of integers. The program should allocate
memory dynamically depending on the value of . [4]
[Hint: You should declare a pointer to int say and using either malloc( ) or
calloc( ) allocate bytes of memory of type int and assign them to . Rest is
easy.]
c) Write a C program that calls a function sum_of_squares(…) with variable length
argument list to return the sum of the squares of the arguments passed to it. [3]
d) Write a C program to perform following operations. [5]
(i) Open a file named Names.txt in write mode.
(ii) Read a list of names through keyboard using gets(…) function.
(iii) Write these names to Names.txt. Each name should be separated by a tab
character.
(iv) Close the file Names.txt and reopen it in read mode.
(v) Read the names from the file and display them on the monitor.
(vi) Close the file Names.txt.
5. a) Recall that the distance between a point ( , ) and a line is
given by the following formula:
Now define a point P and a line L using structs. Write a function that takes a line and
a point as its arguments and returns the distance between them using the above
formula. [4]
b) Discuss how would a array will be stored in Row Major order and
6. 6
Column major order. [3]
c) How will you store the following sparse matrix in vector and linked list
representation so that only nonzero elements are stored? [3]
6. a) Define a node for a list of characters using doubly linked list. Write a function named
move_to_first( ) which takes a pointer to a node of the list and a character
and moves the character to the first location if it exists in the list otherwise displays
the message “Character not found”. Also write a function named display( )
that takes a pointer to node of the list and displays the contents of the list. [7]
b) Explain the procedure how recursion works using stacks. [3]
7. a) Evaluate the expression , , , , , , , , , , in RPN. [3]
b) Manually provide the inorder, preorder and postorder traversals of the following
binary search tree: [6]
c) Draw a binary tree for the expression )/(*)(* QPDCBA [3]
d) Explain the procedure of deletion of a node in a binary search tree. [3]
45
25
12
2
15
26
30
52
50
35
53