PROGRAMMING AND DATA STRUCTURES

2010 Jawaharlal Nehru Technological University, Hyderabad SET-2 Code.No: 09A1EC01 JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD I B.TECH - REGULAR EXAMINATIONS, JUNE - 2010 C PROGRAMMING AND DATA STRUCTURES Question paper

SET-2
Code.No: 09A1EC01
JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD
I B.TECH - REGULAR EXAMINATIONS, JUNE - 2010
C PROGRAMMING AND DATA STRUCTURES
(COMMON TO CE, EEE, ME, ECE, CSE, CHEM, EIE, BME, IT, MECT, E.COMP.E, MMT, MEP, AE, ICE, BT, AME)
Time: 3hours Max.Marks:75
Answer any FIVE questions
All questions carry equal marks
--------------------------
1.a) List out the various steps in software development.
b) Given the 3 sides of triangle a, b and c as input, Draw a flowchart to test whether it is isosceles, equilateral or not. It should also validate whether the input forms a triangle or not. (Ex. 10, 3, 3 is not a triangle) [6+9]
2.a) Write minimal C-expressions for the following:
i) 5a4 +3a3-4a2+6a+12
ii) abcbccaab--
iii) If the given integer value of x is treated as binary, the fifth bit from the right.
iv) Absolute value of variable x.
v) True if x is exactly divisible by 5 but not divisible by 3, otherwise false.
vi) Subtract x from y and then increment x.
b) What is the difference between the following C-words?
i) 253 and 0253
ii) 'r' and '\r'
c) Write C-program for determining whether the given integer at input is perfect number or not. A number is said to be perfect number if the sum of factors is equal to number itself. For example, the factors of 6 are 1, 2, 3 whose sum 1+2+3=6. [6+2+7]
3.a) Write recursive function int gcd(int m, int n) that returns greatest common divisor of m and n where m>n. Write an equivalent iterative version. Compare them. In order to find gcd, if m is exactly divisible by n, then n is the value of gcd, otherwise it is gcd of the n and the remainder of the division. For example. gcd(6,4)=gcd(4,2)=2
b) Write C-function int minpos(float x[], int n) that returns position of the first minimum value among the first n elements of the given array x. [8+7]
4. Consider the following program:
void funtest(int *a, int *b)
{
static int i=10;
int j=5;
j=j+a;
i=i+b;
*a=i;
*b=j;
}
int main()
{
int i=20,j=30, *x, *y;
x=&i;
y=&j;
funtest(x,y);
printf("%d %d %d %d\n",i,j,*x,*y);
funtest(x,y);
printf("%d %d %d %d\n",i,j,*x,*y);
}
Trace the above program execution (changed variable values and bindings of each statement during execution). What is the output of above program? [15]
5. Write C-structures for a country with the following fields: country Name(dynamically allocated string), currency code(3 letter string), number of states and states(dynamically allocated structures). A country can have 1 to 100 states. Each state is associated with name (dynamically allocated string), area, and population. The area of the country is the sum of the areas of all the states in the country. Similarly the population of the country is population of all states put together. Write function void countrystats(struct country *c, int *a, int *b)that computes the area and population of the country and places at locations pointed by a and b. [15]
6.a) List and explain the streams functions for binary files along with their prototypes. b) Write a C-function that takes a binary file of long integers and appends a new long integer at the end that is sum of all integers in the original file. [7+8]
7.a) Write an algorithm or program for sorting integers using bubble sort.
b) Show the bubble sort results for each pass for the following initial array of elements.
35 18 7 12 5 23 16 3 1 [7+8]
8.a) Write an algorithm for evaluating postfix expression. Demonstrate your algorithm with stack contents for each operation using the post fix expression 2 3 5 + *
b) Write structures for Linked list implementation of Stack and a function for pop operation. [8+7]
KEYWORDS:PROGRAMMING AND DATA STRUCTURES,PROGRAMMING AND DATA STRUCTURES QUESTION PAPER,JNTU,JNTU QUESTION PAPER,JAWAHARLAL NEHRU TECHNOLOGICAL UNIVERSITY HYDERABAD REGULAR EXAMINATIONS JUNE PROGRAMMING AND DATA STRUCTURES