Assignment 2
Assignment 2
11. Write a C program to calculate the average of a set of numbers. The program should prompt the user to
enter the number of elements in the set, then prompt the user to enter each element. Finally, the program
should calculate and print the average of the entered numbers using separate functions for input, calculation,
and output. Additionally, use an externalvariable to keep track of the sum of the numbers.
12. Write a C program that simulates a simple banking system. The program should include the following
functionalities:
a. Deposit: Allow the user to deposit a certain amount into their account.
b. Withdraw: Allow the user to withdraw a certain amount from their account.
c. Check balance: Display the current balance in the account.
Use static variables to keep track of the total balance across all transactions. Ensure that the total balance is
shared among all instances of the banking system.
13. Write a C program that simulates a simple online shopping system. The program should include the
following functionalities:
a. Add item to cart: Allow the user to add items to their shopping cart.
b. Remove item from cart: Allow the user to remove items from their shopping cart.
c. View cart: Display the items currently in the user's shopping cart.
Ensure that each user has their own shopping cart, and use local variables to represent the items in the cart.
14. Write a C program that simulates a simple text editor. The program should allow the user to perform
the following
operations on a text string:
a. Append: Append a string to the end of the current text.
b. Insert: Insert a string at a specific position in the current text.
c. Delete: Delete a substring from the current text.
d. Replace: Replace a substring in the current text with another string.
e. Print: Print the current text.
15. Write a C program that calculates the value of a mathematical expression involving trigonometric
functions and logarithms.The program should prompt the user to input the values of variables and evaluate
the expression. Ensure to handle error cases such as division by zero or undefined values.
Sample mathematical expression to evaluate:
sin(x)+cos(y)/log(z)
16. Write a C program that calculates the factorial of a non-negative integer using recursion. The factorial
of a non-negative integer n, denoted as n!, is the product of all positive integers less than or equal to n. The
factorial of n is defined as: n! = n*(n-1)(n-2)..*3*2*1
17. Write a C program that implements a recursive function to generate all possible combinations of a given
set of characters. The program should take a string of characters as input and print all possible combinations
of those characters. For example, given the input string "ABC", the program should generate the following
combinations:
a. ABC
b. ACB
c. BAC
d. BCA
e. CAB
f. CBA
18. Write a C program that defines macros for mathematical operations (e.g., addition, subtraction,
multiplication, division) and uses them to perform calculations. The program should use macros to define
the operations and then demonstrate their usage in various mathematical expressions.
19. Write a C program that defines a function to swap the values of two integers using pointers. The program
should prompt the user to input two integers, call the swap function to swap their values, and then print the
swapped values.
20. Write a C program that takes two nxn matrix as input from the user, calculates the product of the
matrices and prints it.
21. Write a C program that takes an array of integers as input, calculates the sum and average of the elements
using pointers, and then prints the sum and average.
22. Write a C program that defines a function to count the number of vowels in a string using character
pointers. The program should prompt the user to input a string, call the function to count the vowels, and
then print the count.