0% found this document useful (0 votes)
5 views21 pages

C Programming

Uploaded by

Zulkar Ansari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views21 pages

C Programming

Uploaded by

Zulkar Ansari
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Subject- C Programming

Chapter1 Flowchart and Algorithm


Q1. Simple Calculator: Design a flowchart and write a C program for
a calculator that performs basic arithmetic operations (+, -, *, /) on
two numbers. The program should take the operator and two
numbers as input and output the result.

Q2. Finding Maximum of Three Numbers: Design a flowchart and


write a C program to find the maximum of three numbers. The
program should take three numbers as input and output the largest
one

Chapter 2 (Arithmetic Operator)


Q1 Write a program that converts Centigrade to Fahrenheit.
Expected Output :
Input a temperature (in Centigrade): 45
113.000000 degrees Fahrenheit.

Q2 Write a C program that takes hours and minutes as input, and


calculates the total number of minutes.
Expected Output :
Input hours: 5
Input minutes: 37
Total: 337 minutes.

Q3 Write a program in C that takes minutes as input, and display the


total number of hours and minutes.
Expected Output :
Input minutes: 546
9 Hours, 6 Minutes

Q4 Write a C program to perform addition, subtraction,


multiplication and division of two numbers.
Expected Output :
Input any two numbers separated by comma : 10,5
The sum of the given numbers : 15
The difference of the given numbers : 5
The product of the given numbers : 50
The quotient of the given numbers : 2.000000

Chapter 3 Decision Making


Q1. Write a C program to check whether a given number is even or
odd.
Test Data : 15
Expected Output :
15 is an odd integer

Q2. Write a C program to check whether a given number is positive


or negative.
Test Data : 15
Expected Output :
15 is a positive number

Q3. Write a C program to find whether a given year is a leap year or


not.
Test Data : 2016
Expected Output :
2016 is a leap year.

Q4. Write a C program to read the age of a candidate and determine


whether he is eligible to cast his/her own vote.
Test Data : 21
Expected Output :
Congratulation! You are eligible for casting your vote.

[Link] a C program to read the value of an integer m and display


the value of n is 1 when m is larger than 0, 0 when m is 0 and -1
when m is less than 0.
Test Data : -5
Expected Output :
The value of n = -1

Q6. Write a C program to accept the height of a person in


centimeters and categorize the person according to their height.
Test Data : 135
Expected Output :
The person is Dwarf.

[Link] a C program to find the largest of three numbers.


Test Data : 12 25 52
Expected Output :
1st Number = 12, 2nd Number = 25, 3rd Number = 52

Q8. Write a C program to accept a coordinate point in an XY


coordinate system and determine in which quadrant the coordinate point
lies.
Test Data : 7 9
Expected Output :
The coordinate point (7,9) lies in the First quadrant.

Q9. Write a C program to determine eligibility for admission to a


professional course based on the following criteria:
Eligibility Criteria : Marks in Maths >=65 and Marks in Phy >=55 and Marks
in Chem>=50 and Total in all three subject >=190 or Total in Maths and
Physics >=140 ------------------------------------- Input the marks obtained in
Physics :65 Input the marks obtained in Chemistry :51 Input the marks
obtained in Mathematics :72 Total marks of Maths, Physics and Chemistry :
188 Total marks of Maths and Physics : 137 The candidate is not eligible.
Expected Output :
The candidate is not eligible for admission.

Q10 Write a C program to calculate the root of a quadratic equation.


Test Data : 1 5 7
Expected Output :
Root are imaginary;
No solution.

Q11 Write a program in C to accept a grade and declare the


equivalent description :

C programming course
Grade Description

E Excellent

V Very Good

G Good

A Average

F Fail

Test Data :
Input the grade :A
Expected Output :
You have chosen : Average

Q12 Write a program in C to read any digit and display it in the


word.
Test Data :
4
Expected Output :
Four

Chapter 4 Looping
1. Sum of Digits
Write a C program to input a number and calculate the sum of its digits using
a loop.

2. Factorial Calculator
Write a C program to compute the factorial of a given number using
a for loop.

3. Multiplication Table
Write a C program to print the multiplication table of a given number up to
10 using a while loop.
4. Prime Number Checker
Write a C program to check whether a given number is prime or not using a
loop.

5. Fibonacci Series
Write a C program to print the first n terms of the Fibonacci series using a
loop.

6. Number Reversal
Write a C program to reverse a given number using a loop.

7. Pattern Printing
Write a C program to print the following pattern using nested loops:

text

**

***

****

*****

8. Armstrong Number Checker


Write a C program to check if a given number is an Armstrong number using
a loop.

9. Count Digits
Write a C program to count the number of digits in a given integer using a
loop.

10. Power Calculation


Write a C program to calculate x y (where x and y are integers) using a loop
without using the pow() function

11. Number Pyramid


Write a C program to print the following pattern using nested loops:

text

12

123
1234

12345

12. Hollow Square Pattern


Write a C program to print a hollow square pattern of stars. The program
should take the size as input:
For size = 5:

text

*****

* *

* *

* *

*****

13. Diamond Pattern


Write a C program to print a diamond pattern of stars for an odd number of
rows:
For n = 5:

text

***

*****

***

14. Floyd's Triangle


Write a C program to print Floyd's Triangle:

text

23

456

7 8 9 10
11 12 13 14 15

15. Binary Number Triangle


Write a C program to print the following pattern:

text

01

101

0101

10101

Chapter 5 Array
1. Basic Array Operations
Write a C program that:

 Declares an integer array of size 10

 Takes 10 integers as input from the user

 Prints the array in reverse order

 Calculates and prints the sum and average of all elements

2. Find Maximum and Minimum


Write a C program to find the maximum and minimum element in an integer
array. The array size and elements should be taken as user input. Implement
without using built-in functions like max() or min().

3. Element Search in Array


Write a C program that:

 Takes an array of n integers and a target integer as input

 Searches for the target in the array using linear search

 Prints the index of the first occurrence if found, else prints "Not Found"

 Also counts and prints the total number of occurrences of the target

4. Array Rotation
Write a C program to rotate an integer array left by k positions.
Example:
Input: [1, 2, 3, 4, 5], k = 2
Output: [3, 4, 5, 1, 2]

5. Remove Duplicates
Write a C program to remove duplicate elements from a sorted integer array.
Print the modified array and its new length.
Example:
Input: [1, 1, 2, 3, 3, 3, 4]
Output: [1, 2, 3, 4], length = 4

6. Merge Two Sorted Arrays


Write a C program to merge two sorted integer arrays into a third sorted
array. Assume arrays are sorted in ascending order. Do not sort the merged
array after merging—merge in sorted order directly.

7. Frequency Count
Write a C program to count the frequency of each element in an integer
array.
Example:
Input: [2, 3, 2, 5, 3, 7]
Output:
2 → 2 times
3 → 2 times
5 → 1 time
7 → 1 time

8. Matrix Addition
Write a C program to add two 3×3 matrices. Take both matrices as input
from the user and store the result in a third matrix. Print the result matrix in
proper format.

9. Second Largest Element


Write a C program to find the second largest element in an integer array.
Handle cases where all elements are the same or array size is less than 2.

10. Array Partition (Even-Odd Separation)


Write a C program to rearrange an integer array such that all even numbers
appear before odd numbers, while preserving the relative order of even and
odd numbers separately.
Example:
Input: [5, 2, 9, 4, 6]
Output: [2, 4, 6, 5, 9]
Chapter 6 String
1. String Length without Library Functions
Write a C program to find the length of a given string without using any built-
in string handling functions (like strlen()).

2. String Palindrome Check


Write a C program to check if a given string is a palindrome (reads the same
forward and backward). Ignore case and non-alphabetic characters.

3. String Concatenation Manually


Write a C program to concatenate two strings without using strcat().
Implement your own logic to join the second string to the end of the first.

4. Count Vowels and Consonants


Write a C program that takes a string as input and counts the number of
vowels and consonants in it.

5. Remove All Duplicate Characters


Write a C program to remove all duplicate characters from a string. Print the
resulting string with only the first occurrence of each character retained.

6. Find the First Non-Repeating Character


Write a C program to find the first non-repeating character in a given string.
If all characters repeat, print a suitable message.

7. Reverse Words in a Sentence


Write a C program to reverse the order of words in a given sentence. For
example, "Hello World" becomes "World Hello".

8. String Encryption (Caesar Cipher)


Write a C program to encrypt a string using a Caesar cipher. Shift each
alphabetic character by a given integer key (wrap around for 'z' to 'a'). Ignore
non-alphabetic characters.

9. Check for Substring Presence


Write a C program to check if a given substring exists within a main string.
Do not use strstr(). Return the starting index if found, or -1 otherwise.

10. String Compression


Write a C program to perform basic string compression by counting
consecutive repeated characters. For example, "aaabbbbcc" becomes
"a3b4c2". If the compressed string is not shorter, return the original string.
Chapter 7 Function
Question 1: Basic Function Implementation

Write a C program that contains:

 A function isEven() that takes an integer as parameter and returns 1 if


the number is even, otherwise 0

 A function printTable() that takes an integer and prints its multiplication


table from 1 to 10

 A main() function that calls both functions for a user-input number

Question 2: Prime Number Checker

Create a program with:

 A function isPrime() that returns 1 if a number is prime, 0 otherwise

 A function printPrimes() that prints all prime numbers between two


given ranges

 The main() function should take range input from user and display all
primes in that range

Question 3: Mathematical Calculator

Implement a calculator program with these functions:

 add(), subtract(), multiply(), divide() - each taking two floats and


returning result

 calculate() function that takes two numbers and an operator character


(+, -, *, /)

 main() should repeatedly calculate until user chooses to exit

Question 4: Array Operations Using Functions

Write a program with these array functions:

 readArray() - reads array elements from user

 findMax() and findMin() - return maximum and minimum values

 calculateAverage() - returns average of array elements


 main() should demonstrate all functions

Question 5: String Manipulation Functions

Create string functions without using string.h:

 stringLength() - returns length of string

 stringCopy() - copies source string to destination

 stringCompare() - compares two strings

 main() should test all functions with user input

Question 6: Recursive Functions

Implement the following recursive functions:

 factorial() - calculates factorial of a number

 fibonacci() - returns nth Fibonacci number

 sumOfDigits() - returns sum of digits of a number

 main() should demonstrate all three functions

Question 7: Function Overloading Simulation

C doesn't support function overloading, but simulate it by:

 Creating addTwo() function that can add:

o Two integers

o Two floats

o Three integers (using default parameters concept)

 Use different function names or parameter approaches

 main() should demonstrate all versions

Question 8: Number System Conversion

Create conversion functions:

 decimalToBinary() - converts decimal to binary

 binaryToDecimal() - converts binary to decimal

 decimalToHexadecimal() - converts decimal to hexadecimal

 main() should provide a menu-driven conversion program


Question 9: Bank Account System

Implement a banking system with functions:

 createAccount() - initializes account with details

 deposit() - adds amount to balance

 withdraw() - deducts amount with validation

 displayBalance() - shows current balance

 Use structures and functions to manipulate account data

Question 10: Advanced - Function Pointers

Create a program demonstrating function pointers:

 Implement add(), subtract(), multiply(), divide() functions

 Create a function pointer array

 Implement executeOperation() that takes function pointer as argument

 Create a menu-driven calculator using function pointers

Chapter 8 Pointer
Question 1: Basic Pointer Operations

Write a C program that demonstrates:

 Declare an integer variable and a pointer to it

 Display the value, address using &, and pointer dereferencing

 Perform arithmetic operations using pointers (increment, decrement)

 Show the relationship between arrays and pointers

 Demonstrate pointer-to-pointer (double pointer) concept

Question 2: Array Manipulation Using Pointers

Create a program that performs the following array operations using only
pointers (no array subscript notation []):

 Reverse an array

 Find maximum and minimum elements

 Search for a specific element


 Copy one array to another

 Calculate sum and average of array elements


All operations should be implemented as separate functions accepting
pointer parameters.

Question 3: String Operations with Pointers

Implement the following string functions using only pointers (without using
array notation or string.h):

 stringLength() - returns length of string

 stringCopy() - copies source to destination

 stringConcatenate() - concatenates two strings

 stringCompare() - compares two strings

 stringReverse() - reverses a string in place


Each function should take pointer parameters and return appropriate
values.

Question 4: Pointer Arithmetic and 2D Arrays

Write a program that:

 Dynamically allocates a 2D array (matrix) using pointers

 Fills the matrix with user input

 Performs matrix addition and multiplication using pointer arithmetic

 Finds transpose of matrix using pointers

 Calculates sum of diagonal elements

 Deallocates memory properly

Question 5: Dynamic Memory Management

Create a program that demonstrates:

 Dynamic memory allocation for an array of integers

 Reallocation to increase array size

 Implementation of basic operations (insert, delete, search)

 Creation of a dynamic array of structures (Student with name, roll,


marks)
 Sorting the dynamic array using pointer-based sorting algorithm

 Proper memory deallocation and avoiding memory leaks

Question 6: Function Pointers and Callbacks

Implement a program that uses function pointers to:

 Create an array of function pointers for mathematical operations

 Implement qsort()-like function that sorts an array using a comparison


function pointer

 Create a map() function that applies a function to each element of an


array

 Implement a calculator where operations are selected via function


pointers

 Demonstrate callback mechanism for event handling simulation

Question 7: Pointer to Structures

Design a Student Management System using pointers to structures:

 Create a structure Student with name, roll number, and marks array

 Dynamically allocate array of Student structures

 Implement functions for:

o Adding/removing students

o Searching student by roll number (return pointer to student)

o Calculating average marks for each student

o Finding student with highest average

o Sorting students by name or marks

 Use -> operator for structure pointer access

Question 8: Complex Pointer Declarations and Usage

Write a program that demonstrates understanding of:

 Pointer to an integer

 Pointer to a pointer to integer

 Array of pointers to integers


 Pointer to an array of integers

 Pointer to function returning integer

 Array of pointers to functions


Create examples that clearly show the declaration, initialization, and
usage of each type.

Question 9: Memory Manipulation and Pointer Safety

Create a program that:

 Demonstrates common pointer errors (dangling pointer, memory leak,


null pointer dereference)

 Implements safe versions of string functions with bounds checking

 Creates a safeCopy() function that prevents buffer overflow

 Demonstrates proper use of const with pointers

 Shows difference between shallow copy and deep copy using pointers

 Implements a simple memory leak detector

Question 10: Advanced Pointer Application - Linked List

Implement a singly linked list with the following operations using pointers
only:

 createNode() - creates a new node dynamically

 insertAtBeginning() - inserts node at start

 insertAtEnd() - inserts node at end

 deleteNode() - deletes node with given value

 search() - searches for a value

 reverseList() - reverses the linked list

 displayList() - displays all elements

 sortList() - sorts the linked list

 Proper memory management for all operations

Chapter 9 Structure and Union


Question 1: Student Record System

Create a structure Student with the following members:

 roll_no (integer)

 name (string, max 50 characters)

 marks (float array for 5 subjects)

 percentage (float)

Write a program to:

 Read data for N students

 Calculate percentage for each student

 Display student details in tabular format

 Find and display the topper's details

Question 2: Employee Database Management

Define a structure Employee containing:

 emp_id

 name

 department

 salary

 date_of_joining (nested structure containing day, month, year)

Create functions to:

1. Add employee details

2. Display all employees

3. Search employee by ID

4. List employees in a specific department

5. Find employees with salary above a certain amount

Question 3: Library Book System

Design a structure Book with:

 book_id
 title

 author

 is_issued (1 if issued, 0 if available)

 member_id (if issued)

Create a menu-driven program to:

 Add new books

 Issue a book to a member

 Return a book

 Display all available books

 Search book by title/author

Question 4: Complex Number Operations

Define a structure Complex to represent complex numbers (real and


imaginary parts).

Write functions to:

 Add two complex numbers

 Subtract two complex numbers

 Multiply two complex numbers

 Divide two complex numbers

 Display complex number in a+bi format

Create a calculator that performs these operations based on user choice.

Question 5: Student Marks Analysis with Arrays of Structures

Create an array of structures for 50 students. Each structure contains:

 reg_no

 name

 marks[3] (marks in three subjects)

Write functions to:

1. Input student details


2. Calculate total and average for each student

3. Display students who scored above 80% average

4. Find subject-wise toppers

5. Sort students based on total marks

Question 6: Time Calculator

Define a structure Time with:

 hours

 minutes

 seconds

Write functions to:

1. Read two time periods

2. Add two time periods

3. Subtract two time periods

4. Convert time to total seconds

5. Convert seconds to Time structure

Advanced: Handle cases where minutes/seconds exceed 60.

Question 7: Union Demonstration - Storage Optimization

Create a union VehicleInfo that can store information about different


vehicles:

 For cars: model, seating_capacity, fuel_type

 For trucks: load_capacity, number_of_wheels

 For motorcycles: engine_cc, has_sidelight

Write a program that:

 Uses a structure with a vehicle_type tag and the union

 Stores information based on vehicle type

 Displays appropriate information for each vehicle type

Question 8: Bank Account with Transaction History


Define a structure Account with:

 account_number

 customer_name

 balance

 last_transactions (array of structures containing amount, type, date)

Implement functions for:

 Creating new account

 Deposit and withdrawal with balance validation

 Displaying last 5 transactions

 Calculating interest

 Displaying account summary

Question 9: Polygon Area Calculator using Structures

Create structures to represent:

 Point (x, y coordinates)

 Line (two Points)

 Triangle (three Points)

 Rectangle (four Points)

Write functions to:

1. Calculate distance between two points

2. Calculate area of triangle

3. Calculate area of rectangle

4. Check if triangle is right-angled

5. Check if rectangle is a square

Question 10: University Course Registration System

Design structures for:

 Course (course_code, title, credits, instructor)

 Student (student_id, name, enrolled_courses array)


 Faculty (faculty_id, name, courses_taught array)

Create a program to:

 Register students for courses (max 5 courses per student)

 Assign courses to faculty

 Display student timetable

 Display faculty teaching schedule

 Calculate student's total credits

Chapter 10 File Handling


Question 1: Student Database File System

Create a program that maintains a student database in a file. Each student


record should contain:

 Roll Number

 Name

 Marks in 3 subjects

 Total Marks

Implement the following operations:

1. Add new student records to the file

2. Display all student records

3. Search for a student by roll number

4. Update a student's marks

5. Delete a student record

6. Display students with total marks above a certain threshold

File to use: [Link] (binary file)

Question 2: Text File Word Counter and Analyzer

Write a program that reads a text file and:

1. Counts the total number of words, lines, and characters

2. Finds the frequency of each word (case-insensitive)


3. Finds the longest word in the file

4. Finds the most frequent word

5. Creates a new file with the same content but with line numbers

Additional: Remove punctuation marks before counting words.

Question 3: Employee Payroll System

Create an employee payroll system that stores data in a file. Each employee
record should have:

 Employee ID

 Name

 Department

 Basic Salary

 DA, HRA, PF deductions

 Net Salary

Implement:

1. Add employee with salary calculation

2. Generate payslip for a specific employee (save to separate file)

3. Display all employees of a department

4. Generate monthly payroll report in a text file

5. Update employee salary details

Files: [Link] (binary), payslips/ directory for individual payslips

You might also like