```c #include <stdio.h> #include <stdlib.h> typedef struct BankAccount { int balance; } BankAccount; BankAccount* openaccount(int initial_balance) { BankAccount* account = (BankAccount*)malloc(sizeof(BankAccount)); if (account == NULL) { printf("Error: Unable to allocate memory for the account.\n"); exit(1); } account->balance = initial_balance; return account; } void deposit(BankAccount* account, int amount) { if (amount <= 0) { printf("Error: Deposit amount must be positive.\n"); return; } account->balance += amount; } void withdraw(BankAccount* account, int amount) { if (amount <= 0) { printf("Error: Withdrawal amount must be positive.\n"); return; } if (account->balance < amount) { printf("Error: Insufficient balance.\n"); return; } account->balance -= amount; } int getbalance(BankAccount* account) { return account->balance; } int main() { BankAccount* my_account = openaccount(1000); // 开户,初始余额为1000 deposit(my_account, 500); // 存款500 printf("Current balance: %d\n", getbalance(my_account)); // 查询余额 withdraw(my_account, 200); // 取款200 printf("Current balance: %d\n", getbalance(my_account)); // 查询余额 free(my_account); // 释放内存 return 0; } ``` [2024-08-08 14:47:08 | AI写代码神器 | 436点数解答]