Sie sind auf Seite 1von 7

National Institute of Technology

Department of Computer Science and Engineering


MCA – Semester 1
CS2092D – Programming Laboratory
Assignment -2

Submission deadline(on or before)


6th September 2019, 12:30:00 pm

Policies for submission and evaluation


You must submit your assignment in the moodle (EduServer) course page, on or before the submission
deadline. Ensure that your program compile and execute without errors. During evaluation your
program will be evaluated against multiple test cases. For complete mark your program should execute
for all the test cases.
Your submission will also be tested for plagiarism by automated tools. In case your code fails to pass
the test, you will be straightaway awarded 'zero' marks for this assignment and considered by examiner
for awarding 'F' grade in the course. Detection of ANY malpractice regarding the lab course will also
lead to awarding an 'F' grade.

Naming Conventions for Submission


Submit a single .zip file(do not submit any other archived format).
Name of .zip file should be:
ASSG<number>_<rollnumber>_<firstname>.zip
DO NOT add any other file, except your source code, into the .zip file.
Source code of each assignment question should be named as:
ASSG<number>_<rollnumber>_<firstname>_<questionno.>

Standard of Conduct
Violations of academic integrity will be severely penalized. Each student is expected to adhere to high
standards of ethical conduct, especially those related to cheating and plagiarism. Any submitted work
MUST BE an individual effort. Any academic dishonesty will result in zero marks in the corresponding
exam or evaluation and will be reported to the department council for record keeping and for
permission to assign an 'F' grade in the course. The department policy on academic integrity can be
found at:
http://minerva.nitc.ac.in/cse/sites/default/files/attachments/news/Academic-Integrity_new.pdf

General Instructions
Programs should be written in C language and compiled using the C compiler in Linux platform.
Invalid input should be detected and suitable error messages should be generated. Sample inputs are
just indicative. Please do the programs in your free time from Network Systems Lab (NSL), when the
lab is not used for regular lab hours or do the programs using your own computer. Even if the programs
work in your own computer, there is a chance that they may not work properly in the computers in
NSL, due to some compatibility issues of the C compiler or the machine. Hence, before the evaluation
day, check that your programs are ready for execution in the computers in NSL.
Evaluation of following questions will be conducted on 6th September 2019, Friday 2.00 pm-5.00 pm.
National Institute of Technology, Calicut
Department of Computer Science and Engineering
CS2092D Programming Laboratory
Assignment – 2

1. Write a C program to read your Name and find the second last character of your
Name using pointers
Input : A character array
Output : A single character
Output Format
Enter your name : joseph

Second last character is : p

2. Read your register number as a string (in the given format). Extract course, year of
joining, and roll number from your register number using pointers.
Input : A string (of 8 characters: first 3 denotes the course, next 2 denotes the
year of joining, last 3 denotes student's roll number)
Output : Separated course, year of joining and roll number
Output Format:
Enter you register number : MCA19056

Your Course : MCA


Your year of joining : 19
Your roll number : 056

3. Your class representative is collecting the marks of all students from your class in all
subjects. He got the marks of three subjects (English, Mathematics and Data
Structures) and he made a table. After some time he got the marks of C
-Programming Lab too. Now he needs to create a new table which contains Sl.no,
marks of all subjects and total mark (English, Mathematics, Data Structures, C-
programming lab, and Total- marks). Help him to create this new table and display
the final table. Use integer pointers.
Input : Number of students 'n' , nx3 array, 1D array of size n.
Output : an nx6 matrix
Output Format:
Enter number of students : 4
Enter marks of English, Mathematics and Data Structures of 4 students :
88 90 85
65 75 70
50 80 70
70 75 30
Enter marks of C-programming lab of 4 students : 88 75 60 40
Table of marks of 4 students :
1 88 90 85 88 351
2 65 75 70 75 285
3 50 80 70 60 260
4 70 75 30 40 215

4. Write a C program to find the height of N th tallest man standing in a queue in a random order of
their heights.
Input:- An integer number to get total number of men in queue, an integer array with height of
each man and an integer number to get the value of 'N'
Output : An integer number denoting the height of Nth tallest man.

Output Format:
Enter number of men in the queue : 5
Height of 5 men : 8 6 5 9 1
Enter the value of 'N' : 3

Height of 3rd tallest man is : 6

5. You are given an array of unsorted numbers. Find two numbers from the array whose sum is
equal to any user input number. If two numbers exist return TRUE else FALSE.
Input : Size of array, an integer array of unsorted elements and an integer number
Output : A string

Output Format:
Enter size of array : 5
Enter array elements : 8 7 9 0 1
Input number : 15

TRUE

6. Write a menu driven C program to implement Binary search in an input array.


Menu should give option for doing Binary search in iterative and recursive form.
Input : An unsorted integer array, an integer number to search.
Output : An integer number
Output Format:
MENU
------------------------------------
1. BinarySearch_iterative
2. BinarySearch_recursive
Enter '0' to exit
---------------------------------------
Enter your option : 1
Enter size of array : 5
Enter array elements : 8 7 9 0 1
Search element : 9

9 is found at position 3

Enter your option : 0

7. Define a function diagonalSum() that takes a 2D array as parameter and return TRUE if sum of
its diagonals are equal, else return FALSE.
(Use dynamic memory allocation)
Input : A 2D integer array
Output : A character array

Output Format:
Enter size of array : 3
Enter elements to 3x3 matrix : 1 2 3
4 5 6
7 8 9

TRUE

8. Define two functions dec-bin() and bin-dec() that does following task:
dec-bin() : Takes an integer number and convert it to binary
bin-dec() : Takes a sequence of 1s and 0s and convert to decimal.
Both functions should return the result to main().
[Do it as menu driven program]
Input : An integer number to select the choice.
According to the choice, either an integer number or a sequence of 1s and 0s
Output: According to the choice, either a sequence of 1s and 0s or an integer number.

Output Format:
MENU
------------------------------------------
1. Convert from decimal to binary
2. Convert from binary to decimal
Enter '0' to exit
-------------------------------------------
Enter your choice: 1
Enter the number : 5
Binary equivalent of 5 = 101

Enter your choice : 2


Enter the binary number : 11
Decimal equivalent of 11 = 3

Enter your choice: 0

9. Define two functions findLargest() and removeLargest().


FindLargest() : Returns the largest element in the argument array.
RemoveLargest() : Excludes the element that is returned from findLargest() from the argument
array and returns the resultant array to main().
Input: An integer array of size 'n'
Output : An integer array of size 'n-1'

Output Format :
Enter size of array : 5
Enter array elements : 56 78 91 12 45

Largest element in array : 91


Resultant array : 56 78 12 45

10. Write a menu driven C program to display the nth term in Fibonacci series.
Program should give options as below:
1. Fibonacci using Iteration
2. Fibonacci using Recursion
Both the function should print execution time.
[Hint : Fibonacci series – 0 1 1 2 3 5 … . Refer the link for calculating execution time
https://www.geeksforgeeks.org/how-to-measure-time-taken-by-a-program-in-c/ ]

Input : An integer number 'n'


Output : nth Fibonacci number

Output Format:
MENU
------------------------------------
1. Fibonacci_iterative
2. Fibonacci_recursive
Enter '0' to exit
---------------------------------------
Enter your option : 2
Enter value of n : 5

5th term of Fibonacci series is : 3


Time taken is 0.19999 seconds
Enter your option : 0

11. Define a recursive function digitSum(), that displays sum of digits, up to a single digit, of an
entered number.
Input : An integer number
Output : A single digit integer number.

Output Format:
Enter a digit : 4863
Digit sum = 3 (Hint: 4+8+6+3=21 and 2+1=3)

12. Enter an integer number 'n'. Define a recursive function OddandEven() to print all even and
odd numbers separately in the range of 1 to n.
Input : an integer number
Output : 2 integer arrays

Output Format:
Enter a limit : 10
All even numbers from 1 to 10 : 2 4 6 810
All odd numbers from 1 to 10 : 1 3 5 7 9

13. Define a function printPercentage() to read a number and print 1% to 100% of that number
Input : An integer number
Output : 100 floating point numbers

Output Format:
Enter a number : 1340

1% of 1340 = 13.4
2% of 1340 = 26.8
3% of 1340 = 40.2
.
.
100 % of 1340 = 1340.0

14. Define two functions findLCM() and findGCD(), that takes two integer numbers as arguments
and return their LCM and GCD respectively.
[Note : Use Euclid's algorithm to find GCD]
Input : Two integer numbers
Output : An integer number

Output Format:
Enter two numbers : 6 4

LCM of 6 and 4 = 12
GCD of 6 and 4 = 2

Das könnte Ihnen auch gefallen