 ASSIGNMENT II IN ‘C’

B.C.M. II YEAR

Session 2007-2008

NOTE : Students are required to submit program listings alongwith output reports by 15.02.2010. A soft copy of all the programs (Assignment I and II) should also be submitted with the file on CD.

SECTION - II

1. Given an N x N matrix. Write a program which prints the sum of the elements

(i)         above the main diagonal.

(ii)        below the main diagonal, and

(iii)       diagonal elements.

2. An array A contains 25 positive integers. Write a program which finds and prints all pairs of elements whose sum is less than or equal to 25.

3. Each student in a class of N students takes six tests in which scores range between 0 and 100. Suppose the test scores are stored in an N x 6 array TEST. Write a menu driven program which:

a)      finds the average marks for each test.

b)      finds the total marks for each student where total marks is the sum of the student's five highest test scores.

c)      finds the no. of students who have failed i.e. whose total marks are less than 250.

4.      An array A contains N elements. Write a program using functions that calculates the arithmetic and geometric means.

5.      Suppose A is an M x N matrix. Write a program using function which finds the element of A with largest absolute value.

6.      Write a program that counts blanks, digits, letters and special characters in a given text.

7.      Suppose an array A[N] contains K elements (such that K< N) which are in increasing order and suppose a new element D is to be inserted in its proper place if it is not  already present in A. Write a program using function that inserts D in its proper position in A.

8.      Write a program using function to compute Binomial Coefficient :

nCr  = n!/((n-r)!*r!) where n, r ³ 0 and n ³ r.

9.      Write a function, say is-fib-prime(int n), that generates nth Fibonacci number and calls another function is-prime (int n ) to test whether the generated no. is a prime no.

10.  A palindrome is a string that reads the same both forward and backward. Some examples are:  “1234321”, “C”, “ABCBA”. Write a function that takes a string as an argument and returns 1 if the string is a palindrome and 0 otherwise.

11. The annual examination results of 100 students are tabulated as follows: Roll No.           Subject1               Subject2                  Subject3  Write a program to read the data and determine the following:

a)  Total marks obtained by each student.

b)  The highest marks in each subject and the Roll no. of the student who secured it.

c)  Roll-Nos. of first three position holders.

12. Give the matrices A and B of sizes m x n and n x q respectively. Write a program that finds matrix C of size m x q which is the product of A and B and whose elements are defined as :

n

Cij        =           å aik * bkj

k=1

Write a program that will read the values of elements of A and B and produce the product matrix C.

13. Write a function  that accepts a 2-digit positive integer and prints it in words. For example 56 should be printed as “Fifty Six”.

14.  Write a program to extract a portion of a character string and print the extracted string. Assume that m characters are extracted, starting with the nth character.

15.  Write a program which will read a string and write it in the alphabetical order. For example, the word STRING  should be written as GINRST.

16.  Write a program to replace a particular word by another word in a given string for example, the word “PASCAL” should be replaced by “C” in the text “It is good to program in PASCAL language.

17.  A simple encryption scheme is to interchange letters of the alphabet on a one-to-one basis.       This can be accomplished with a translation table for the 52 lower and uppercase letters. Write a program that uses such a scheme to encode text. Write another program that will decode text that has been encoded. (Note that this is not a serious encryption scheme. If you are interested to know more about encryption, check out on-line manual on UNIX concerning “Crypt” to get the flavour of some of the concerns in the area of encryption.

18.  Write a menu-driven program to print marksheet of a given student of BCM Ist year.

**********************