C Example: Bank Accounts: deposit, withdraw, transfer and balance checks

🗓 Last updated: 2026-11-30👤 Written by: Harper✓ Reviewed by: MOTO🏷 Category: Mini Apps

Implements deposit, withdraw and account-to-account transfer with account structs; every operation first checks a positive amount and sufficient balance, printing a rejection instead of changing the balance. Prints final balances for three accounts, demonstrating validate-then-mutate.

⚡ Intermediate Reference entries: kw-structfn-printfkw-double
🖥 Run OnlineGCC 10.2 · C11 standard · click ▶ to run · Copy code
🖨 Reference OutputMatches the online run in a standard C11 environment
C · GCC 10.2 · -std=c11
deposit 300.00 -> #1001 balance 1500.00
withdraw 700.00 from #1002 rejected (balance 540.50)
withdraw 50.00 -> #1003 balance 30.00
transfer 200.00 #1001 -> #1003: 1300.00 / 230.00
deposit rejected: amount must be positive

final balances:
  #1001 Ada    1300.00
  #1002 Grace  540.50
  #1003 Linus  230.00
🧩 Keep Learning

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏