0% found this document useful (0 votes)
9 views10 pages

C Program Question Bank Based On CO1 To CO5

The document outlines a comprehensive curriculum covering arrays, pointers, strings, structures, and file handling in programming. It includes various learning objectives (COs) with specific programming tasks and concepts to be understood and implemented. Each unit is structured to enhance understanding through practical coding exercises and theoretical explanations.

Uploaded by

guptamayank50443
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
9 views10 pages

C Program Question Bank Based On CO1 To CO5

The document outlines a comprehensive curriculum covering arrays, pointers, strings, structures, and file handling in programming. It includes various learning objectives (COs) with specific programming tasks and concepts to be understood and implemented. Each unit is structured to enhance understanding through practical coding exercises and theoretical explanations.

Uploaded by

guptamayank50443
Copyright
© © All Rights Reserved
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/ 10

Unit I: Arrays

CO1: Understanding Array Fundamentals


1. Define an array. Explain its advantages and limitations with suitable examples.

2. Write a program to declare a one-dimensional array that stores the prices of 5 different products. Display
the entered values along with their total sum.

3. Explain the difference between static and dynamic array allocation with examples.
4. Write a program that inputs 10 integer values into an array and finds the even and odd numbers
separately. Display both groups.

5. Describe different types of arrays and provide practical scenarios where each type is useful.

CO2: Implementation and Manipulation of One-Dimensional Arrays


1. Write a program to input marks of 5 students and calculate their average using an array.

2. Develop a program that takes an array of integers and calculates the sum of elements at even indices.

3. Write a program that copies the contents of one array into another array.

4. Implement a program that reverses the elements of an array without using any additional array.

5. Write a program to count the frequency of each unique element in an array.

CO3: Sorting Arrays


1. Write a program to sort an array of 10 integers using the Bubble Sort algorithm.

2. Implement a program that sorts an array in descending order using the Insertion Sort algorithm.

3. Write a program that sorts an array of strings in alphabetical order.

4. Implement a program that sorts an array of integers and identifies the second largest element.

5. Write a program to sort an array of student names and search for a specific name using binary search.

CO4: Arrays and Functions


1. Write a program that accepts an array of integers as input and calculates the maximum value using a
function.

2. Implement a function that accepts two arrays and merges them into a single sorted array.

3. Write a program that calculates the sum of all prime numbers in an array using a function.

4. Develop a program that passes an array to a function that checks whether the array is palindromic
(same forwards and backwards).
5. Write a program that takes an array as input, passes it to a function, and returns the smallest difference
between any two elements in the array.

CO5: Two-Dimensional and Multidimensional Arrays


1. Write a program to input a 3x3 matrix and display the elements in matrix format.

2. Implement a program that calculates the sum of diagonal elements of a square matrix.

3. Write a program that multiplies two 3x3 matrices and displays the resulting matrix.

4. Develop a program that stores and displays elements of a 3D array representing a 3x3x3 cube.

5. Explain Row Major Order and Column Major Order with suitable examples and implement a
program to demonstrate both memory representations.
Unit II: Pointers
CO1: Understanding Pointer Fundamentals
1. Define a pointer. Explain the relationship between pointers and memory addresses with suitable
examples.

2. Write a program to declare a pointer, assign it the address of an integer variable, and display both the
value and the address of the variable using the pointer.

3. Explain the concept of NULL pointer and wild pointer with examples.

4. Write a program that demonstrates pointer arithmetic by incrementing and decrementing a pointer to
navigate through an integer array.

5. Describe the difference between pointer variables and normal variables with code examples.

CO2: Pointer Operations and Manipulation


1. Write a program that swaps two integers using pointers.

2. Implement a program that reverses the contents of a character array (string) using pointers.

3. Write a program that finds the maximum and minimum elements in an array using pointers.

4. Develop a program to calculate the sum of array elements using pointers.

5. Write a program that dynamically allocates memory for an integer array using malloc() or calloc() and
demonstrates proper memory deallocation using free().

CO3: Pointers with Functions


1. Write a function that accepts two integer pointers and swaps their values without using a third variable.
2. Implement a function that calculates the factorial of a number using pointers.

3. Write a program that demonstrates pass-by-reference using pointers in a function to modify the original
values.

4. Develop a program that accepts an array from the user and passes it to a function to calculate the
average of its elements.

5. Write a program that uses a pointer to traverse and print the characters of a string.

CO4: Pointers with Arrays and Strings


1. Write a program that sorts an array of integers using pointers.

2. Implement a program that copies the contents of one string into another using pointers (without using
built-in string functions).
3. Develop a program that finds the length of a string using pointers.

4. Write a program that compares two strings using pointers (without using strcmp()).

5. Implement a program that concatenates two strings using pointers.

CO5: Advanced Concepts in Pointers (Dynamic Memory, Structures, etc.)


1. Write a program that dynamically allocates memory for a structure containing student information
(name, roll number, and marks) and displays the stored details.

2. Implement a program that uses a pointer to an array of pointers to store and display multiple strings.

3. Write a program that creates a linked list using pointers with operations like insertion, deletion, and
display.

4. Develop a program that performs matrix multiplication using pointer-based dynamic memory
allocation.

5. Write a program that demonstrates the use of function pointers by implementing a calculator that
performs addition, subtraction, multiplication, and division.
Unit III: Strings
CO1: Understanding String Fundamentals
1. Define a string. Explain how strings are represented in C/C++ with suitable examples.

2. Write a program to input a string from the user and display it character by character using a loop.

3. Explain the difference between character arrays and string literals with suitable examples.

4. Write a program that counts the number of vowels, consonants, and digits in a given string.

5. Describe how the null character (\0) is used to terminate a string and demonstrate its significance with
code.

CO2: String Manipulation Techniques


1. Write a program to reverse a given string without using any built-in string functions.

2. Develop a program that converts a string to uppercase and lowercase using ASCII values.

3. Write a program to check whether a given string is a palindrome or not.

4. Implement a program that counts the number of words in a given sentence.

5. Write a program that removes all spaces from a string.

CO3: String Searching and Sorting


1. Write a program to find the first occurrence of a given character in a string.

2. Develop a program that checks if one string is a substring of another.

3. Write a program to count the number of times a particular word appears in a sentence.
4. Implement a program that sorts a list of strings in lexicographical order.
5. Write a program that replaces all occurrences of a specified character in a string with another character.

CO4: Strings and Functions


1. Write a function that accepts a string as a parameter and returns its length.

2. Develop a program that uses a function to concatenate two strings without using strcat().

3. Write a function that checks whether a given string contains only numeric digits.

4. Implement a function that accepts a string and returns the number of unique characters in it.

5. Write a program that takes two strings as input and checks if they are anagrams of each other using a
function.
CO5: Advanced String Concepts (Dynamic Memory, Pointers, etc.)
1. Write a program that dynamically allocates memory for a string, accepts input, and displays the string
along with its length.

2. Develop a program that finds and prints the longest word in a given sentence.

3. Write a program that uses pointers to compare two strings without using strcmp().

4. Implement a program that counts the frequency of each character in a string using an array or dictionary.

5. Write a program that encrypts a given string using Caesar Cipher and decrypts it back to the original
text.
UnitIV : Structures
CO1: Understanding C Preprocessor Basics
1. Define the C Preprocessor. Explain its role in the compilation process and describe its key features.

2. Write a program that demonstrates the use of #define to create symbolic constants for mathematical
values like Pi (π), e, and other constants.

3. Explain the purpose of the #include directive. Demonstrate the difference between angle brackets (<>)
and double quotes ("") when including header files.

4. Write a program that shows the use of #undef to remove a previously defined macro and redefine it with
a new value.
5. Describe the difference between predefined macros like __FILE__, __LINE__, and __DATE__ with a
program that prints their values.

CO2: Macro Expansion and Inline Code


1. Write a program that defines a macro SQUARE(x) that calculates the square of a number. Demonstrate
its usage with different inputs.

2. Create a macro MAX(a, b) that returns the maximum of two numbers using the conditional operator.

3. Write a program using a macro that calculates the area of a circle using the formula: Area = πr².

4. Develop a program that defines a macro for swapping two values without using a third variable.

5. Write a macro ABS(x) that returns the absolute value of a number and demonstrate its use with both
positive and negative values.

CO3: Conditional Compilation


1. Write a program that demonstrates the use of #if, #elif, #else, and #endif directives to implement
conditional compilation based on a defined macro.

2. Implement a program that defines a macro for the DEBUG mode. Display additional debugging
information only if the DEBUG macro is defined.

3. Write a program that uses #ifdef and #ifndef to ensure certain code sections are included only when
specific macros are defined.

4. Develop a program that uses #pragma directives to suppress compiler warnings for specific sections of
code.

5. Write a program that implements two versions of a function — one for Windows and one for Linux —
using conditional compilation.
CO4: File Inclusion and Header Guards
1. Write a program that demonstrates the use of header guards (#ifndef, #define, #endif) to prevent
multiple inclusions of the same header file.
2. Create two custom header files — one for mathematical operations and another for string operations.
Write a main program that includes and utilizes both.

3. Develop a program that dynamically switches between including <stdio.h> and <iostream> depending
on whether the __cplusplus macro is defined.

4. Write a program that creates a configuration header file to manage environment-specific settings like
file paths, buffer sizes, etc.

5. Develop a program that demonstrates nested file inclusion and explains its impact on compilation.

CO5: Advanced Preprocessor Techniques


1. Write a program that implements token pasting (##) to combine two identifiers into a new variable.

2. Develop a program that utilizes the stringizing operator (#) to convert a macro argument into a string.

3. Write a program that creates a macro that expands into a loop structure to simplify repetitive code
patterns.

4. Implement a program that demonstrates the use of the __VA_ARGS__ macro to handle variable
argument lists in macros.

5. Create a program that conditionally includes platform-specific libraries (e.g., <windows.h> for Windows
and <unistd.h> for Linux) using advanced preprocessor techniques.
Unit V : File handling
CO1: Understanding File Handling Basics
1. Define file handling. Explain the importance of file handling in C with examples.

2. Write a program to create a text file named "data.txt" and write the following information into it:

o Name

o Age

o Marks

3. Explain the difference between text files and binary files with suitable examples.

4. Write a program that opens a file and counts the number of characters, words, and lines in it.

5. Explain the purpose of the following file handling functions with examples:

o fopen()
o fclose()

o fgetc()

o fputc()

CO2: File Writing Operations


1. Write a program that accepts user input and appends it to an existing file called "log.txt".

2. Develop a program that writes the multiplication table of a given number into a file.

3. Write a program that accepts a paragraph from the user and saves it into a file named "paragraph.txt".

4. Implement a program that writes the details of multiple students (Name, Roll Number, Marks) into a file
using fprintf().
5. Write a program that accepts a list of product details (Name, Price, Quantity) from the user and writes
them to a file named "products.txt".

CO3: File Reading Operations


1. Write a program that reads a text file called "info.txt" and displays its contents on the screen.

2. Develop a program that reads a file containing student marks and calculates the average marks.

3. Write a program that reads the contents of a file and converts all the lowercase characters into
uppercase before displaying it.

4. Implement a program that reads a list of integers from a file and identifies the largest and smallest
number.
5. Write a program that reads the contents of a file and displays only the lines that contain the word
"ERROR".

CO4: File Manipulation and Searching


1. Write a program that searches for a given word in a text file and displays its line number(s) if found.

2. Develop a program that reads a file containing employee details and displays the record of employees
earning above $5000.

3. Write a program that replaces all occurrences of a given word in a file with another word.

4. Implement a program that reads data from one file and writes the reversed content into another file.

5. Write a program that merges the contents of two text files into a third file.

CO5: Advanced File Operations and Error Handling


1. Write a program that demonstrates random access in a file using fseek() and ftell() functions.
2. Develop a program that appends a timestamp to a log file every time the program runs.

3. Write a program that creates a binary file containing employee records (ID, Name, Salary) and reads
those records.

4. Implement a program that securely copies a file’s content to another file and verifies the file sizes to
ensure data integrity.
5. Write a program that creates a menu-driven system for managing a file-based student database with
options for:

o Adding records

o Searching for a student by ID


o Modifying a record

o Deleting a record

You might also like