Practice Programs for Adv C Prog
Practice Programs for Adv C Prog
(Autonomous)
Department of Computer Studies
F.Y B.Sc. (Computer Science)
Academic Year: 2024-25
SEM-II
Advanced C Programming - Practice Programs
1
4. Write a program to print even number and odd numbers in an array using an array of pointers.
5. Write a program to search a particular number present in an array or not using an array of pointers.
6. Write a program to check whether the given number is palindrome or not using array of pointer.
7. Write a program to compute the area and perimeter of a Rectangle. Accept required Input and
display desired output using an array of pointers.
1. Write a program to find the sum of the element in an array using malloc function.
2. Write a program to print the addition of matrices using calloc & free function.
3. Write a program to find even or odd numbers in an array using malloc function.
4. Write a program to count duplicate number in an array using dynamic memory allocation.
5. Write a program to read an array and print reverse of an array using dynamic memory
Allocation.
6. Write a program to find maximum element in an matrix using dynamic memory allocation
7. Write a program to compute the area and perimeter of a circle. Accept required
input and display desired output using dynamic memory allocation
8. Write a program to convert decimal numbers into binary numbers using dynamic memory
allocation.
Assignment 4: Functions
1. Write a C program which returns the factorial of a given number using a function.
2. Write a C program, which accepts a character and integer n as parameter and displays the next n
characters using a function.
3. Write a function isPrime, which accepts an integer as parameter and returns 1 if the number is
prime and 0 otherwise. Use this function in main to display the first 10 prime numbers.
4. Write a function isEven, which accepts an integer as parameter and returns 1 if the number is
even, and 0 otherwise. Use this function in main to accept n numbers and check if they are even or
odd.
5. Write a C program to calculate the sum of digits of a given number using a function.
6. Write a function to accept a number and calculate the cube of a given number.
2
7. Write a menu driven program to perform the following operations till the user selects Exit. Accept
two complex numbers from the user (real part, imaginary part). Write a separate function for each
operation.
i. ADD
ii. SUBTRACT
iii. MULTIPLY
iv. EXIT
8. 4. Write a function to check whether a given number is an armstrong number or not. (Ex.
153=(1*1*1)+(5*5*5)+(3*3*3), is an armstrong number.)
1. Write a C program to accept n numbers and calculate the range of elements in the array. Write
separate functions to accept and calculate.
2. Write a C program to accept n numbers in an array and calculate the average. Write separate
functions to accept and calculate.
3. Write a C program to accept a matrix A of size m x n and store its transpose in matrix B. Display
matrix B. Write separate functions to accept and display.
4. Write a C program to add two matrices to accept, display, add and multiply the matrices. Perform
necessary checks before adding and multiplying the matrices. Write separate functions to accept
and display.
5. Write a C program to accept n numbers and count Even and Odd Elements in an Array. Write
separate functions to accept and display.
6. Write a menu driven program to perform the following operations on a square matrix. Write
Separate functions for each option.
i. Display 2 matrices
ii. Display addition
iii. Display subtraction
iv. Exit
7. Write a C program to accept n numbers and print Array Elements Present in Even Position. Write
separate functions to accept and display.
8. Write a C program to accept 1-D array and display sorted array. Write a separate function to
accept and sort.
3
Assignment 6: Recursive Functions
1. Write a recursive function to calculate the sum of digits of a number. Use this function in main to
accept a number and print sum of its digits.
2. Write a C program to check whether a given number is prime or not using a recursive function.
3. Write a recursive function to calculate the GCD of two numbers. Use this function in main. The
GCD is calculated as :
gcd(a,b) = a if b = 0
= gcd (b, a mod b) otherwise
4. Write a C program to calculate product of numbers without using of ‘*’ operator using a recursive
function.
5. Write a C program to calculate x^y using a recursive function.
6. Write a C program to calculate LCM of two numbers using recursive function.
7. Write a recursive function to calculate the nth Fibonacci number. Use this function in main to
display the first n Fibonacci numbers. The recursive definition of nth
Fibonacci number is as follows:
fib(n) = 1 if n = 1 or 2
= fib(n-2) + fib(n-1) if n>2
8. Write a C program using recursive function to calculate the sum of digits of a number till you get
a single digit number. Example: 961 -> 16 -> 5. (Note: Do not use a loop).
9. Write a recursive C function to print the digits of a number in reverse order. Use this function in
main to accept a number and print the digits in reverse order separated by tab.
Example 3456 - 6543
(Hint: Recursiveprint(n) = print n if n is single digit number
= print n % 10 + tab + Recursiveprint( n/10)
10. Write a recursive function for the following recursive definition. Use this function in main to
display the first 10 numbers of the following series
an = 3 if n = 1 or 2
= 2* an-1 + 3*an-2 if n > 2
1. Write a C program using a function pointer to check whether a number is even or odd using a
function pointer.
4
2. Write a C program to check if number is positive, negative or zero using a function pointer.
3. Write a C program that swaps the values of two integers using pointers. Pass the integer variables
to the function using pointers and print the values before and after swapping.
4. Write a C program to accept a character from user and update it to next character. Display updated
character in main function.
5. Write a C program where a function takes an integer as an argument, dynamically allocates
memory for an array of that size, and returns a pointer to the array. The main function should print
the values in the array.
6. Write a C program where a function takes an array of integers and its size as input, and returns a
pointer to the largest element in the array.
7. Write a C program to calculate the average of an array of numbers using a function pointer.
8. Write a C program to calculate the length of a string using a function pointer.
9. Write a C program where a function accepts two integers as pointers, calculates their product and
sum, and prints both values. The result should be printed in the main function.
10. Write a C program that returns a pointer to a dynamically allocated array from a function. The
function should fill the array with values, and the main function should print the values in the
array.
5
10. Write a program which accepts a sentence from the user and alters it as follows: Every space is
replaced by *, case of all alphabets is reversed; digits are replaced by?
1. Accept employee details (emp. No., Name, phone number) from the user and display details in
proper format.
2. Accept bank details (A/c no. Holder name, a/c type, balance) and display all details in proper
format.
3. Accept student information (Roll No., Name, 5 Subject Marks) from the user and display the
calculated result(Roll No., Name, 5 Subject Marks, Total and Percentage).
4. Accept employee details (emp. No., Name, phone number, birth date, designation) from the user
and display details in a proper format.
5. Accept details of n employees (emp. No., Name, phone number) from the user and display details
in proper format.
6. Accept details of n bank account (A/c no. Holder name, a/c type, balance) and display all details
in a proper format.
7. Accept bill details ( bill no., Item Name, Quantity, Price per item) from the user and display the
bill( bill no., Item Name, Quantity, Price per item, Total bill) and apply 18% GST on the total bill.
8. Accept n number of student information (Roll No., Name, 5 Subject Marks) from the user and
display the calculated result(Roll No., Name, 5 Subject Marks, Total and Percentage).
9. Accept order details that contain details of n bills (Order no, Bill no., Item Name, Quantity, Price
per item) from the user and display the bill (bill no., Item Name, Quantity, Price per item, Total
bill) and apply 18% GST on the total bill.
10. Create a structure student (roll number, name, marks of 3 subjects). Accept student details and
write a menu-driven program to perform the following operations.
i. Modify the roll number
ii. Modify the student’s name
iii. Display student details only
iv. Display the student’s result.
6
Assignment 10: Structures - Pointers and Structures, Structure and Functions
1. Write a C program to accept employee details (emp. No., Name, phone number) from the user,
pass it to the display() function, and display all the employee details in a proper format.
2. Write a C program to accept employee information (emp. number, name, phone number) from the
user, and pass information to the update() function. Accept the name and phone number in the
update() function, and update the details. Display the employee’s updated information in the
main() function proper format.(hint : call by reference)
3. Write a C program to accept details of n employees (emp. No., Name, phone number) from the
user, pass it to the display() function, and display all the employee details in a proper format.
4. Write a C program to accept details of n book (book No., Book Name, Author Name, Phone
number) from the user, pass it to the update() function and Accept the name and phone number in
the update() function, and update the details. Display the book’s updated information in the main()
function proper format.
5. Create a structure with two strings. Accept one string from the user and perform the following
operations. Write a separate function for the different options.(using call by reference)
i. Copy one string into another string.
ii. Convert 2nd string into the upper letter.
iii. Compare both strings.
v. Display both strings.
6. Write a C program to create a structure for the student details (roll number, name, marks of 3
subjects, percentage). Accept details of n students and write a menu-driven program to perform
the following operations. Write separate functions for the different options.(using call by value)
i. Search
ii. Modify
iii. Display all student details
iv. Display the student having a maximum percentage
7. Write a program to create a structure employee (id, name, salary). Accept details of n employees
and write a menu-driven program to perform the following operations. Write separate functions
for the different options.
i. Search by id
ii. Display all
iii. Display employee having maximum salary
8. Write a C program to create a structure Fraction (numerator, denominator). Accept details of n
7
fractions and write a menu-driven program to perform the following operations. Write separate
functions for the different options. Use dynamic memory allocation. Note: While accepting
fractions, store the fractions in the reduced form.
i. Display the largest fraction
ii. Display the smallest fraction
iii. Display all
1. Write a program to show how to use a union to store multiple data types.
2. Write a program to accept employee details (emp. No., Name, phone number) from the user and
display details in proper format.
3. Write a program to accept bank details (A/c no. Holder name, a/c type(saving or current or joint),
balance) and display all details in the proper format.
4. Write a program to accept employee details (emp. No., Name, phone number) from the user, pass
it to the display() function, and display the details in a proper format.
5. Write a program to store integer value or character value, select the second value from the outer
union according to the first value-
1. If the first value is an integer then store this first value in another variable and accept another
integer value from the user which is the outer union data member value and display at most
two numbers.
2. If the first value is a character then store this first value in another variable and accept another
character from the user which is the outer union data member value and display the next
character of both characters.
6. Write a program to accept student details (roll no., name, and percentage) from the user, pass the
reference of student details to the display() function and display details in proper format.
7. Write a program to create a union movie (name, release year, duration). Accept details of n
movies.
8. Write a program to create a union car (car number, car model name, car color, car cost). Accept
details of n cars and display details in function.
8
Assignment 12: File Handling
1. Write a C program to accept a character from the user and write it to a file.
2. Write a C program to read a text file and display only capital letters from it.
3. Write a C program to read a text file and count the number of lines, characters and words from it.
4. Write a C program to copy contents of one file into another file.
5. Write a program to accept two filenames as command line arguments. Copy the contents of the
first file to the second such that the case of all alphabets is reversed.
6. Write a C program to reverse the first n characters in a file.(Use fseek())
7. Write a C program to display the size of the file.
8. Write a program which accepts a filename and an integer as command line arguments and
encrypts the file using the key. (Use any encryption algorithm)
***