0% found this document useful (0 votes)
12 views

C-Lab Cycles Test Cases

Uploaded by

Mercy Saji
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views

C-Lab Cycles Test Cases

Uploaded by

Mercy Saji
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

S2 CSE

C- PROGRAMMING LAB
LAB EXERCISES

Cycle-1

1. Write a C program for finding the biggest number among 3 numbers.


a) Input -5 4 3 - Output - 4
b) Input 666 - Output - 6 , The numbers are equal
c) Input -15 -4 0 - Output - 0

2. Find the roots of a quadratic equation in the form ax^2 + bx + c = 0. (if ..


else)
a) Input 1 -2 1 - Output - Roots are real & equal - 1.00, 1.00
b) Input 8 -4 -2 - Output - Roots are real, unequal
root1 =0.81 root2 = -0.31
c) Input 2.3 4 5.6 - Output - Roots are Imaginary
-0.87 + 1.30i and -0.87 -1.30i
3. Write a C program to read weekday numbers and print weekday names. (switch)
a) Input 1 - Output - Sunday
b) Input 5 - Output - Thursday
c) Input -1 - Output - Invalid input
d) Input 9 - Output - Invalid input
4. Check whether a particular date (dd-mm-yyyy format) is valid in the range 01-01-
1900 to 31-12-2022. (switch)
a) Input 29-02-1900 - Output - Invalid date
b) Input 29-02-2000 - Output - Valid date
c) Input 31-04-2001 - Output - Invalid date
d) Input 25-13-1999 - Output - Invalid date
e) Input 29-02-2017 - Output - Invalid date
5. Find the largest and smallest of a set of N numbers. (while / do ..while)
a) Input 6 -> -3 1 2 12 8 100 - Output -> 100, -3
b) Input 5 -> -3 -2 -91 -68 -21 - Output -> -2, -91
c) Input 4 -> 21 0 6 7 - Output -> 21,0

6. Find the GCD and LCM of two numbers. (while / do ..while)


a. Input 18,24 - Output - GCD=6, LCM=72
b. Input 15,24 - Output - GCD=3, LCM= 120
c. Input -98,56 - Output -GCD=14, LCM= 392
d. Input 13,10 - Output - GCD=1, LCM= 130

7. Display the first N prime numbers. (nested loop)


a. Input 5 - Output - 2,3,5,7,11
b. Input 1 - Output -2
c. Input 10 - Output - 2,3,5,7,11,13,17,19,23,29
d. Input 0 - Output - Invalid

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

11. Sort N integers in ascending order using bubble sort algorithm.


a. Input 5 56,34,11,78,12 - Output - 11,12,34,56,78
b. Input 0 - Output - Inavalid input
c. Input 6 -23,8,0,-34,67,89 - Output - -34,-23,0,8,67,89
12. Display the binary equivalent of an unsigned decimal integer. (using 1-D array)
a. Input 127 - Output - 1111111
b. Input 14 - Output - 1110
c. Input 43 - Output - 101011
d. input 0 - Output - 0

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

b. Input Set1- 5 - 1, 3,7,7,11


Set2- 6 - 34,1,2,3,11,11
Output -Union - 1,2,3,7,11,34
Inter - 1,3,11
Minus - 7

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.

Input 3X3 - 123


456
789
Output - sum of 1 row - 6 sum of 1 column - 12
sum of 2 row - 15 sum of 2 column - 15
sum of 3 row - 24 sum of 3 column - 18
Sum of boundary elements - 40

Input 3X4 - 1231


4561
7891
Output - sum of 1 row - 7 sum of 1 column - 12
sum of 2 row - 16 sum of 2 column - 15
sum of 3 row - 25 sum of 3 column - 18
sum of 4 column - 3

Sum of boundary elements - 37

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.

Input - First matrix 3 X 3 - 123 Second matrix - 2 X 3


456
789
Output - Multiplication not possible

Input - First matrix 2 X 3 - 1 2 3 Second matrix - 3 X 2 1 2


456 23
34
Output - 14 20
32 47
Input - First matrix 3 X 3 - 1 2 3 Second matrix - 3 X 3 1 2 3
456 233
789 343
Output - 14 20 18
32 47 45
50 74 72

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

Input : Why are you late today


Output : y - 3 times
a - 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

22.Write a function for checking whether a positive integer number is prime or


not. Using this function displays the prime numbers in a mxn matrix.

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.

Input : n=5 r=3 output: 5C3=10


Input : n=4 r=4 output: 4c4=1
input : n=0 r=0 output: 0c0= 1

24.Write a function for checking whether a string is palindrome. Using this


function displays the palindrome words in a line of text.

Input: malayalam is our mother tongue Output: malayalam


Input: wow it's awesome output: wow
input: good morning all output : no palindrome word

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.

Input: total numbers:6 numbers: 36,25,22,12,11,8 key: 22


output: arranged order= item present
Input: total numbers:6 numbers: 36,25,22,12,11,8 key: 8
output: arranged order= item present
Input: total numbers:6 numbers: 36,25,22,12,11,8 key: 25
output: arranged order= item present
Input: total numbers:6 numbers: 36,25,22,12,11,8 key: 36
output: arranged order= item present
Input: total numbers:5 numbers: 13,18,21,30,34 key:12
item not presented
26.Write a program for finding the product of two matrices. Write separate
functions for Reading matrices, Multiplication of matrices and Display
matrix.

Input A= 1 2 3 B= 10 11 output: 140 146


45 6 20 21 320 335
30 31

Input A= 1 2 3 B= 10 11 output: not possible to multiply


45 6 20 21

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

Input B= 10 11 output: L1=11


20 21 L2=21

Input B= 15 12 22 output: L1=22


20 21 24 L2=24
18 14 12 L3=18

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.

You might also like