6
Programs 1. Write a program that reads a list of names and sort the list in Alphabetical order. 2. Write a program in 'C' language that accepts a string as input and checks whether it is a Palindrome or not. 3. Write a program that finds the sum of the 1 st 'n' terms of SIN (X) series. 4. Write a program that finds the sum of the 1 st 'n' terms of COS (X) series. 5. Write a program to illustrate technique of recursion for evaluating the Fibonacci series given by f (0) =1; f (1)=1; f (n)= f (n —1) + f(n — 2) ; 6. Write a 'C' programme using ternary if-then-else operator to evaluate the following function. f (x) = 1 if x > 0 = 0 if x = 0 = -1 if x <0 7. Write a 'C' program to evaluate the following function: f(x) = x + 1, if x < 5 = x + 2, if 5≤ x≤ 10 = 0, otherwise. 8. Write a function which takes three integers as input and returns the smallest of them. The function uses if-else statements only. 9. Write a recursive function which takes a non-negative integer n as a parameter and returns n! 10. Write a program to print the following output. For example, if n = 3 the output is as follows: 1 1 2 1 1 2 2 1 11. Write a program to print the following output 'n' rows. For example, if n=3 then output is as given below:

Questions

Embed Size (px)

DESCRIPTION

Questions

Citation preview

Page 1: Questions

Programs

1. Write a program that reads a list of names and sort the list in Alphabeticalorder.

2. Write a program in 'C' language that accepts a string as input and checkswhether it is a Palindrome or not.

3. Write a program that finds the sum of the 1st 'n' terms of SIN (X)series.

4. Write a program that finds the sum of the 1 st 'n' terms of COS (X)series.

5. Write a program to illustrate technique of recursion for evaluating theFibonacci series given by

f (0) =1;f (1)=1;f (n)= f (n —1) + f(n — 2) ;

6. Write a 'C' programme using ternary if-then-else operator to evaluate thefollowing function.

f (x) = 1 if x > 0= 0 if x = 0 = -1 if x <0

7. Write a 'C' program to evaluate the following function:

f(x) = x + 1, if x < 5 = x + 2, if 5≤ x≤ 10 = 0, otherwise.

8. Write a function which takes three integers as input and returns thesmallest of them. The function uses if-else statements only.

9. Write a recursive function which takes a non-negative integer n as aparameter and returns n!

10. Write a program to print the following output. For example, if n = 3 theoutput is as follows:

11 2 1

1 2 2 1

11. Write a program to print the following output 'n' rows. For example, if n=3then output is as given below:

Page 2: Questions

12. Write a function which takes a 5x5 square matrix of real entries andreturns its trace.

13. Write a program in C' language for the addition of two matrices.

14. Write a function which takes a square matrix as a parameter and returnstrue if the matrix is skew - symmetric, and false otherwise.

15. Write a program to create a matrix A [2] [3] with elements 2, 4, 6, 8, 10,12. Write a program to change the size of above matrix A by adding onecolumn and making the elements of column as 5 times the value ofelements in column 2 of the original matrix.

16. Write a program that creates a file and store some text in the file.17. Write a program in 'C' that accepts a filename as input and prints its

contents to standard output.18. A commercial bank has introduced an incentive policy of giving a bonus to

all its deposit holders. The policy is as follows. If the depositor is a malesenior citizen, he is paid a bonus of 5% of the balance held on 31stDecember. If the depositor is a female senior citizen, she is paid a bonus of7% of the balance held on 31st December. If the depositor falls in neithercategory, a bonus of 2% of the balance held on 31st December is paid.Write an interactive C programme that reads the balance on 31stDecember, sex and age of the depositor and prints the bonus amount.

19. The area of a triangle with sides a, b, and c is given by Area = (s(s—a)(s—b)(s—c))1/2 , where s = (a + b + c)/ 2. Declare a data structure called "Triangle" having threemembers a, b, c of type int. Write a program that prints the area of atriangle, using the above formula.

20. Write a program which solves t2 -6t + 2= 0 iteratively. Your program shouldterminate either after 10 iterations or the difference between thesuccessive approximations becomes less than 10 -4. The initialapproximation to the root may be taken as 0.

Page 3: Questions

Descriptive Questions

Miscellaneous

1. Comparison:1) Call by value/ Call by reference2) Structure/ Union3) Macro/ Function4) Bitwise OR/ Exclusive OR5) Global variable/ Local variable6) Auto variable/ Static variable7) Malloc()/ Calloc()8) While loop/ Do while loop

2. Explain:1) Escape sequence2) Switch-case-default statement3) Break statement4) Continue statement5) Operator6) strcmp ( ) 7) strcat ( )8) fprintf ( )9) fscanf ( )10) Enumerator data type with example11) L-value and R-value12) Indexed sequential file organisation

3. (i). Evaluate: 2 — 4/ (5*(6<3) +1) (ii). Evaluate: 2<3 && 5< = 5 —1(iii). Arrange in the ascending order of priority: ( ), <, &&, +, *

4. Write a macro in C language to find the smallest of three given numbers.5. Write C printf statements for printing the number 573.423 using.

a. 8 place right justified. b. 8 place left justified with only two decimal digits.

6. Declare a structure that stores a 3 - dimensional vector. Also write a functionthat returns the norm of the vector stored in the structure you declared.

7. Declare a structure called “comp” that stores a complex number. Declare avariable of type "comp". Also, write a function that takes a comp variable as a parameter andreturns its modulus.

Page 4: Questions

Binary Tree

8. Write a program in 'C' language for the creation of a Binary Tree.9. Draw the 'binary tree’ by using the following In-order and Pre-order traversals

of a binary tree.In-order: E A C K F H D B GPre-order: F A E K C D H G B

10. Draw the 'binary tree’ by using the following In-order and Post-ordertraversals of a binary tree.

11. The in-order and pre-order tree traversals for a binary tree are given below : 6 7 8 9 10 11 12

10 7 6 9 8 12 11 construct the binary tree.

12. Define the term complete binary tree. Show that the number of nodes at kth

level in a complete binary tree is 2k.

13. Write the Step-by-step procedure to create a BST with the following nodes:32, 48, 11, 22, 8, 62, 26, 14 Also, give the procedure for deleting the node "22" from BST.

14. Construct a Binary Search Tree with the following keys : 5, 7, 3, 10, 19, 4, 6.

15. Construct a Binary Search Tree with the following keys : 3, 6, 9, 2, 1, 5, 7, 8.

16. Write post-order and pre-order traversal of the below binary tree

17. Write the post-order traversal of the binary tree given below, giving all thesteps involved.

Page 5: Questions

Stack, Queue, Linked List

18. Write any two advantages and any two disadvantages of using pointer in 'C'.19. State any two advantages/disadvantages of a circular queue over the linear

queue.20. What is a Priority Queue? Write anyone advantage of it.21. Write one advantage and one disadvantage of Doubly Linked Lists over

Circular Linked Lists.

22. Explain the process of evaluating an expression in reverse polish notationusing a Stack.

23. Evaluate the following expression by using the stack: 5, 15, 5, —, 2, 3, +, /, +.Terms in the expression are separated by commas.

24. Write a program for implementation of a STACK. Use PUSH and POP functionsfor insertion and deletion of an element respectively. PUSH is an operation forinserting an element into the STACK and POP in an operation to remove anelement from STACK.

25. Define a mode for stack implementation using pointers. Write PUSH and POPfunction for your implementation.

26. Write a program for implementation of a linear queue. The program shouldinclude the following operations:

insertion deletion display

27. Write a program in 'C' language for the implementation of a singly linked list.The program should include the following operations:

Creation of Singly linked list insertion of nodes into the Singly linked list Deletion of nodes from Singly linked list Display function

The elements in the singly linked list should be sorted. Use pointers.

28. Assume that a singly linked list stores state names, their capitals and the no.of districts arranged in the ascending order of state names. For example,

Declare a nodefor this list. Also write a function called initialize( ) which initializes the listwith the data "Chhattisgarh", "Raipur" and 27.

29. Assume that a doubly linked list stores the country names and their capitals,arranged in ascending order of country names for example,

Page 6: Questions

Declare a node for the list. Also, write a function that inserts a new node atthe proper place.

30. The login names and passwords of some users are stored in a linked list ofwhich a node is defined below : Struct User { char login_name[20]; char password[151 - ; struct user *Next; ); typedef struct user USER ;

Write a function that takes as input two strings S1 and S2 and a pointer oftype USER and returnsa. The string "USER NOT FOUND" if the string S1 doesn't exist in the list. b. The string "PASSWORD INCORRI CT" if the string S1 exists in the list but S2

doesn't exist in the list. c. The string "SUCCESS" if both the strings S1 and S2 exist in the list.