C-Lab Cycles Test Cases
C-Lab Cycles Test Cases
C- PROGRAMMING LAB
LAB EXERCISES
Cycle-1
8. Input a binary number and display the decimal equivalent of that number. (while /do
.. while)
a. Input 1111111 - Output - 127
b. Input 1110 - Output - 14
c. Input 101011 - Output - 43
d. input 0 - Output - 0
9. Display the perfect numbers in first N counting numbers. ( nested loop)
a. Input 1 - Output - No perfect numbers
b. Input 10 - Output - 6
c. Input 500 - Output - 6, 28, 496
10. Search for a particular number in a list of N numbers using linear search. Display the
position of the number in the list if the number is present. Otherwise display a
suitable message.
a. Input 5 56,34,11,78,12, Key = 12 - Output - index- 4
b. Input 0 - Output - Inavalid input
c. Input 6 -23,8,0,-34,67,89 Key =22 - Output - Key not present
d. Input 5 53,32,-11,78,1, Key = -11 - Output - index- 2
Cycle-2
13. Search for a number in a sorted list of numbers using binary search.
a. Input 5 12,45,67,89,91 Key= 45 - Output - Present at 2
b. Input 0 - Output - Inavalid input
c. Input 6 -23,0,34,67,89 Key = 89 - Output - Present at 5
d. Input 5 1,4, 5,7,9 Key = 10 - Output - Not present
e. Input 5 1,4, 5,7,9 Key = 5 - Output - Present at 3
14. Given two sets (mathematical set) of numbers A and B. Find AUB, A∩B, A-B.
a. Input Set1- 5 - 1, 3,7, 12,11
Set2- 6 - 34,1,2,3,11,5
Output -Union - 1,2,3,5,7,11,12,34
Inter - 1,3,11
Minus - 7,12
15. Given two sorted lists of numbers. Merge these two lists to form a new list such that
the resultant list is also in sorted order. (do the operation without further sorting).
Input 5 - 1, 3,7,11,12
6 - 4,9,13,19,25,30
Output - 1,3,4,7,9,11,12,13,19,25,30
Input 5 - -1,0,3,7,11
6 - 0,0,13,19,25,30
Output - -1,0,3,7,11,13,19,25,30
16. Find the smallest element in the mxn matrix. Also display the position of this
smallest element. {Smallest element may appear more than once in the matrix}
Input 3X3 -
123
456
789
Output - smallest element 1 at position 11
Input 3X3 -
-1 2 3
4 0-6
7 -8 9
Output - smallest element -8 at position 32
Input 3X3 - 1 2 3
4 0 6
7 8 0
Output - smallest element is 0 at position 22 and 33
17. Find the sum of elements in each row, each column of an m x n matrix. Also find the
sum of the boundary elements of the matrix.
18. Check whether a given square matrix is symmetric. If not symmetric, display the
transpose of the matrix.
Input 3X3 -
123
456
789
Output - Not Symmetric Transpose - 1 4 7
258
369
Input 3 X 3 - 1 2 3
256
369
Output - Symmetric
19. Multiplication of two matrices.
20. Find the alphabet which is occurring more times in a line of text. Also display its
frequency.
Input : Hello how are you
Output : o - 3 times
21. Input N student names and arrange them in alphabetical order using exchange sort.
Input : Number of names : 5
: Zyla , Zeona, Ali, Najeeb, Neel
Output: Ali, Najeeb, Neel,Zeona, Zyla
Cycle 3
Input: m=4,n=3 1, 3, 8
27, 11, 13
17, 22, 25
30, 31, 35
Output : 3,11,13,17,31
Input: m=3 n=3 12, 35, 5
71, 11, 13
17, 99, 26
Output : 11,13,17
23.Write a recursive function for finding factorial. Using this function, find nCr.
25.Write a recursive function for binary search. Using this function check
whether a number is present in a list of numbers arranged in descending
order.
27.Write a function for finding the largest number in a one dimensional array.
Using this function display the largest element in each row of a mxn
matrix.
Input A= 1 2 3 output: L1=3
45 6 L2=6
Cycle-4
22. Write a function for checking whether a positive integer number is prime or not.
Using this function display the prime numbers in a mxn matrix.
23. Write a recursive function for finding factorial. Using this function find nCr.
24. Write a function for checking whether a string is palindrome. Using this function
display the palindrome words in a line of text.
25. Write a recursive function for binary search. Using this function check whether a
number is present in a list of numbers arranged in descending order.
26. Write a program for finding the product of two matrices. Write separate functions
for Reading matrices, Multiplication of matrices and Display matrix.
27. Write a function for finding the largest number in a one dimensional array. Using
this function display the largest element in each row of a mxn matrix.
Cycle-5
28. Store the regno, name and 4 marks of a set of students in an array of structure and
display the details along with total marks in the descending order of total marks.
29. Implement the following string library functions using pointers :
1. string length (int StringLengh(char *s))
2. string copy ( void StringCopy(char *s1, char *s2) )
3. string comparison ( int StringCompare (char *s1, char *s2))
4. string concatenation ( void StringConcat(char *s1, char *s2) )
30. Write a program to find the smallest number in a list of integers using command line
argument.
31. Write a program to create a linked list. Each node in the list contains account
number, account name and amount in account. Input an account number and display
the details corresponding to that account. If not present display suitable message.
Repeat the search operation.
32. Using command line arguments copy the content of one text file to another after
converting all lower case letters to upper case.
33. Implement wc command in UNIX.
34. A text file ‘STUDENT.DAT’ contains regno, name and 6 marks in the following
format:
Regn Name Mark Mark Mark3 Mark4 Mark5 Mark
o 1 2 6
6 25 3 3 3 3 3 3
Input a register number and display the marklist corresponding to that student.
Repeat the process if the user wants to continue.
35. You are given an unformated file named “STOCK.DAT” contains the following
information:
Item_Code (char(5)), Item_Name (Char(30)), Unit_Price (float), Qty_Stock (float)
Write a C program to accept the item_code and quantity_purchased of N items and
display the bill for the customer in the following format :
SlNo Item_Code Item_Name Unit_Price Quantity Price
1.
2.
........
N.
Total Price :
Also update the stock file by deducting the quantity sold from the quantiy in stock.
Assume that there is sufficient quantity of all items in stock.