We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2
24CS101 – PROGRAMMING IN C
MODULE BANK 2 – Section 37
A.Y: 2024-2025, Sem – 1 1. Arrays • Develop a program to initialize an array of integers with values 1 to 10 and print the elements using a loop. • Develop a function to find the second largest element in the array without sorting it. The function should return the index of the second largest element, not just the value. • Develop a program that takes an array of integers and removes all duplicates from the array in- place (without using additional memory). The program should then print the new array. 2. Arrays (Multidimensional) • Develop a program to declare a 2D array of integers and initialize it with some values. Print all elements row by row. • Develop a function that calculates the sum of elements in each row and column of a 2D array. The function should modify the array to replace each element with its row sum (or column sum). • Implement a program that performs transpose of a matrix in-place (without using any additional memory) and prints the result. Ensure that the solution works even for non-square matrices. 3. Strings • Develop a program to input a string and print its length without using the built-in strlen() function. • Develop a function to concatenate two strings without using strcat(). The function should take pointers to the two strings as arguments and modify the first string with the concatenated result. • Develop a function that implements a case-insensitive comparison between two strings, where the function returns 0 if they are the same (ignoring case) and non-zero if they are different. 4. Strings (Advanced) • Develop a program to input a string and check if it is a palindrome (using pointers). • Develop a function that implements the strchr() function (finds the first occurrence of a character in a string), using pointers. The function should return a pointer to the character if found, or NULL if not. • Develop a program that finds the longest common substring between two strings using a sliding window technique. This should be done without dynamic programming, and the program should print both the length and the substring. 5. Pointers and Arrays • Develop a program to print all elements of an array using pointer notation. • Develop a function that takes a pointer to an array of integers and finds the sum of all elements. The function should also modify the array by doubling the value of each element. • Develop a program that reverses the elements of an array using pointer arithmetic (i.e., swap elements from both ends of the array). Do not use additional memory (i.e., no extra arrays). 6. Structures • Define a structure called Student with fields for name, roll number, and marks. Develop a program to initialize and print the structure. • Develop a program that creates an array of Student structures, inputs data for multiple students, and prints their details using a function that takes pointers to the structures. • Develop a program that finds the student with the highest marks in an array of Student structures and prints the name and roll number of the top student. 7. Unions • Define a union named Data that can store an integer, float, and character. Develop a program to store and display each type of data in the union. • Develop a program to create a union that stores either a date (day, month, year) or a time (hour, minute, second). Implement functions to print and modify both types. Use pointers to access and modify the union fields. • Develop a program that uses a union to implement a basic polymorphism simulation. The union should hold a generic data type (e.g., int, float, char), and the program should provide functions to set and get data of different types using pointers. 8. Pointers and Structures • Write a program that defines a structure to represent a Book with fields for the title, author, and price. Declare a pointer to the structure and access its members using the pointer. Initialize and print the structure's values. • Write a program that defines a structure called Employee with fields for ID, name, and salary. Create an array of Employee structures and write a function that accepts a pointer to this array and prints the details of all employees who have a salary greater than a specified value (passed to the function). • Write a program that defines a structure called Student with fields for name, age, and marks. The program should: ➢ Create an array of Student structures. ➢ Use pointers to pass the array to a function that calculates the average marks of all students. ➢ The program should print the names and details of all students who have marks greater than or equal to the average. 9. File Handling • Develop a program to open a file in write mode, write a string to it, and then close the file. • Develop a program to read the content of a file line by line and print it to the console, using fgets() to handle large files efficiently. • Implement a program to read a text file, count the number of occurrences of a specific word (provided by the user), and print the word's frequency. Use pointer-based file operations to process the file efficiently. 10. Memory Management • Develop a program that dynamically allocates memory for an array of integers, inputs values from the user, and prints the array. • Develop a program to dynamically allocate memory for a 2D array (matrix) using malloc() and perform matrix addition. Ensure that memory is freed after the operation. • Implement a memory pool using malloc() and free(). The program should simulate memory allocation for variable-sized blocks, allow the user to request, release, and check memory blocks. Additionally, track and print the total memory usage.
Python Advanced Programming: The Guide to Learn Python Programming. Reference with Exercises and Samples About Dynamical Programming, Multithreading, Multiprocessing, Debugging, Testing and More