luc079.c (2686B)
1 /* 2 * Author : Amit Dutta <amitdutta4255@gmail.com> 3 * Date : 08 Feb 2026 4 * Repo : https://github.com/notamitgamer/bsc 5 * License : MIT License (See the LICENSE file for details) 6 */ 7 8 /* Create a structure for bank customers (Acc no, Name, Balance). Write functions to print low balance customers and handle deposits/withdrawals. 9 */ 10 /* Let Us C, Chap- 17 (Structures), Qn No.: B(b) */ 11 12 /* This file is auto-generated by a bot. */ 13 /* This code is not compiled; it is for reference only. */ 14 15 16 #include <stdio.h> 17 #include <string.h> 18 #include <stdlib.h> 19 20 struct customer 21 { 22 int acc_no; 23 char name[50]; 24 float balance; 25 }; 26 27 void print_low_balance(struct customer *c, int n); 28 void transaction(struct customer *c, int n, int acc, float amount, int code); 29 30 int main() 31 { 32 struct customer bank[200] = { 33 {1001, "Alice", 5000.0}, 34 {1002, "Bob", 500.0}, 35 {1003, "Charlie", 1200.0}, 36 {1004, "David", 800.0}, 37 {1005, "Eve", 2000.0} 38 }; 39 int n = 5; 40 int acc, code; 41 float amt; 42 43 // Task 1: Low Balance 44 printf("--- Customers with Balance < Rs. 1000 ---\n"); 45 print_low_balance(bank, n); 46 47 // Task 2: Transaction 48 printf("\n--- Transaction Menu ---\n"); 49 printf("Enter Account No, Amount, Code (1=Deposit, 0=Withdraw): "); 50 scanf("%d %f %d", &acc, &amt, &code); 51 52 transaction(bank, n, acc, amt, code); 53 54 return 0; 55 } 56 57 void print_low_balance(struct customer *c, int n) 58 { 59 int i; 60 for (i = 0; i < n; i++) 61 { 62 if (c[i].balance < 1000) 63 { 64 printf("Acc: %d, Name: %s, Bal: %.2f\n", c[i].acc_no, c[i].name, c[i].balance); 65 } 66 } 67 } 68 69 void transaction(struct customer *c, int n, int acc, float amount, int code) 70 { 71 int i, found = 0; 72 for (i = 0; i < n; i++) 73 { 74 if (c[i].acc_no == acc) 75 { 76 found = 1; 77 if (code == 1) // Deposit 78 { 79 c[i].balance += amount; 80 printf("Deposit successful. New Balance: %.2f\n", c[i].balance); 81 } 82 else if (code == 0) // Withdraw 83 { 84 if (c[i].balance - amount < 1000) 85 { 86 printf("The balance is insufficient for the specified withdrawal (Must maintain min 1000).\n"); 87 } 88 else 89 { 90 c[i].balance -= amount; 91 printf("Withdrawal successful. New Balance: %.2f\n", c[i].balance); 92 } 93 } 94 else 95 { 96 printf("Invalid transaction code.\n"); 97 } 98 break; 99 } 100 } 101 if (!found) printf("Account number not found.\n"); 102 }