Practical 1 A
Find the biggest of three numbers using a nested ternary (conditional) operator.
Practical 1 B
Practical 2A
Practical 2B
Practical 3A
Practical 3B
Practical 4B
Practical 5
Practical 6A
Practical 6B
Practical 7
Practical 8
Practical 9
Practical 10
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct Account {
int accNumber;
char name[100];
float balance;
};
struct Account accounts[100];
int accountCount = 0;
// Function prototypes
void createAccount();
void deposit();
void withdraw();
void checkBalance();
void menu();
int main() {
menu();
return 0;
}
void menu() {
int choice;
do {
printf("\n====== Bank Management System ======\n");
printf("1. Create Account\n");
printf("2. Deposit\n");
printf("3. Withdraw\n");
printf("4. Check Balance\n");
printf("5. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch(choice) {
case 1: createAccount(); break;
case 2: deposit(); break;
case 3: withdraw(); break;
case 4: checkBalance(); break;
case 5: printf("Thank you for using the system.\n"); break;
default: printf("Invalid choice! Please try again.\n");
}
} while(choice != 5);
}
// Function to create an account
void createAccount() {
struct Account newAccount;
[Link] = accountCount + 1; // Auto-increment account
number
printf("Enter account holder's name: ");
getchar(); // clear input buffer
fgets([Link], sizeof([Link]), stdin);
[Link][strcspn([Link], "\n")] = 0; // Remove
newline
printf("Enter initial deposit amount: ");
scanf("%f", &[Link]);
accounts[accountCount] = newAccount;
accountCount++;
printf("Account created successfully! Your account number is %d\n",
[Link]);
}
// Function to deposit amount
void deposit() {
int accNum, found = 0;
float amount;
printf("Enter account number: ");
scanf("%d", &accNum);
for(int i = 0; i < accountCount; i++) {
if(accounts[i].accNumber == accNum) {
printf("Enter amount to deposit: ");
scanf("%f", &amount);
if(amount < 0) {
printf("Invalid amount.\n");
return;
}
accounts[i].balance += amount;
printf("Amount deposited successfully.\n");
printf("New balance: %.2f\n", accounts[i].balance);
found = 1;
break;
}
}
if(!found) {
printf("Account number %d not found.\n", accNum);
}
}
// Function to withdraw amount
void withdraw() {
int accNum, found = 0;
float amount;
printf("Enter account number: ");
scanf("%d", &accNum);
for(int i = 0; i < accountCount; i++) {
if(accounts[i].accNumber == accNum) {
printf("Enter amount to withdraw: ");
scanf("%f", &amount);
if(amount < 0) {
printf("Invalid amount.\n");
return;
}
if(amount > accounts[i].balance) {
printf("Insufficient balance.\n");
} else {
accounts[i].balance -= amount;
printf("Withdrawal successful.\n");
printf("Remaining balance: %.2f\n", accounts[i].balance);
}
found = 1;
break;
}
}
if(!found) {
printf("Account number %d not found.\n", accNum);
}
}
// Function to check balance
void checkBalance() {
int accNum, found = 0;
printf("Enter account number: ");
scanf("%d", &accNum);
for(int i = 0; i < accountCount; i++) {
if(accounts[i].accNumber == accNum) {
printf("Account holder: %s\n", accounts[i].name);
printf("Balance: %.2f\n", accounts[i].balance);
found = 1;
break;
}
}
if(!found) {
printf("Account number %d not found.\n", accNum);
}
}