PCS251
PCS251
2. Contact Hours: L: 0 T: 0 P: 4
6. Semester: 2
9. Course After completion of the course the students will be able to:
Outcome:
CO1: Understand and apply concepts of multi-dimensional arrays and
strings for providing solutions to homogenous collection of data.
CO2: Understand and apply the concept of pointers involving operations
on strings, overcome the limitations of arrays and handle
heterogeneous collection of datatypes using structures & union.
CO3: Apply concepts of file handling to implement data storage,
manipulation and searching operations.
CO4: Understand and implement the working of user defined functions
to provide solutions to basic problems, strings, and file manipulation
using python scripts.
10. Details of the Course:
Sl. List of problems for which student should develop program and execute Contact
No. in the Laboratory Hours
Week 1: (2D Array)
• Develop a C program to test whether a given matrix of order M × N is an upper
triangular matrix or not. An upper triangular matrix is the one in which all the
elements below its principal diagonal are zero.
1. • Write a C program to read two square matrices of non-zero elements of order M
X M and then subtract the elements of the second matrix from the first matrix.
Then display the resultant matrix to the console.
• Develop a C program to read a square matrix M x M & then find the sum of the
elements around the peripheral. Display their final sum to the console.
Week 2: (2D Array)
• Develop a C program to accept the names in a 2-D array and then search a name
entered by the user. Display an appropriate message to the output screen if
found.
• Develop a C program to read two square binary matrices of order N x N from the
2. user and perform the XOR on the elements of the matrices and print the resultant
matrix to the output screen.
• Design a UDF that returns the by swapping all the elements about the principal
diagonal of a matrix. Develop a C program to implement the function by accepting
the rows and columns in the main program. Display the swapped matrix in the
calling program.
N = the size of the population, xi = each value from the population µ = the
population mean.
• Write a C program to accept N integers from the user into an array. If any integer
is positive then subtract 2 from it, if integer is negative add 1 to it and if zero then
do nothing. Implement a UDF using a pointer to perform these operations and
finally display the modified array to the screen in the calling program.
Sample Input:
1 3 -5 0 8 -4 -1
Output:
-1 1 -4 0 6 -3 0
Week 6: (Pointers & Strings)
• Design a UDF using pointer that returns 1 if the string is a palindrome otherwise
zero. Accept a string from user in the calling program. Display an appropriate
6.
message in the calling program. Implement a C program for the same. Ignore
the case.
Sample Input/Output:
Input:
Enter a String: Rotator
Output:
Rotator is a palindrome
• Design a UDF that returns the count of special characters present in a sentence
passed to it using pointer to the calling program. Implement a C program to read
a string in the main program and display all the count of the special characters
returned by the function to the console.
Sample Input:
Enter a String: Rotation%# is$? ?rotating $motion?
Output:
Special Character Count: 10
• Design a UDF that takes a single string and a character present in the string as
its argument, then it returns an index to the first occurrence of the character to
the string. Write a C program to read a sentence in the main program and display
the string from the index returned by the UDF using a pointer to the console.
Sample Input:
Jack and Jill went up the hill
Search Character: ‘w’
Output: went up the hill
Week 7: (Pointers)
• Write a C program to dynamically allocate memory for an integer array of size N,
allow the user to input N integers, resize the array to N+M using realloc to add M
more integers, compute the sum of all N+M integers, and properly release the
allocated memory.
• Write a C program to dynamically allocate memory for two user-input strings,
7. concatenate them into a new dynamically allocated string, print the result and free
all allocated memory.
• Write a C program to dynamically allocate memory for an array to input N integers
and then create a second dynamically allocated array to store only the prime
numbers of the N integer array. Print the resultant array and free all the allocated
memory.
Week 8: (Structures)
• Develop a program in C to read a structure in the main program of an Employee
that contains Name, EmpCode and Salary as the members. Write a function to
display the details of the employee in the following format.
ABCCorporation
Name : Aman Singh
8. Bha
EmpCode : E211
Nett.Salary : Rs.1,25,000
-
• Develop a C program to read the attributes of an item from the user such as
ItemCode, ItemName, Quantity and Rate. Implement a C program using a
structure to find the total cost of the inventory of storing N items in the stock.
• Develop a C program to find total and average sales of 'N' employees by reading
the details such as empcode, name, and sales using array of structures.
Week 9: (Structures and Union)
• Develop a C program to display Name, Roll Number, Date of Birth and Date of
Admission details of a student read from the keyboard where the date of birth
and date of admission further consists of three members such as day, month and
year in a separate structure. Implement using a C structure.
• Develop a C program to read the following details of N employees into
9.
appropriate data storage. EmpNo, Name and Salary. Display all the details of the
employees in the descending order of their salary to the console.
• Write a C program to define a union with fields int id, float salary, and char
name[20], input values for each field, print the stored values, and demonstrate
how the union can hold only one value at a time by modifying and printing the
fields.