Skip to content

luc079.c

Problem Statement

Create a structure for bank customers (Acc no, Name, Balance). Write functions to print low balance customers and handle deposits/withdrawals.

Metadata

Property Detail
Author Amit Dutta amitdutta4255@gmail.com
Date 08 Feb 2026
License MIT License (See the LICENSE file for details)

Actions

Raw View on GitHub

💡 You can print or save this file by opening Raw and using your browser.

Source Code

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

struct customer
{
    int acc_no;
    char name[50];
    float balance;
};

void print_low_balance(struct customer *c, int n);
void transaction(struct customer *c, int n, int acc, float amount, int code);

int main()
{
    struct customer bank[200] = {
        {1001, "Alice", 5000.0},
        {1002, "Bob", 500.0},
        {1003, "Charlie", 1200.0},
        {1004, "David", 800.0},
        {1005, "Eve", 2000.0}
    };
    int n = 5;
    int acc, code;
    float amt;

    // Task 1: Low Balance
    printf("--- Customers with Balance < Rs. 1000 ---\n");
    print_low_balance(bank, n);

    // Task 2: Transaction
    printf("\n--- Transaction Menu ---\n");
    printf("Enter Account No, Amount, Code (1=Deposit, 0=Withdraw): ");
    scanf("%d %f %d", &acc, &amt, &code);

    transaction(bank, n, acc, amt, code);

    return 0;
}

void print_low_balance(struct customer *c, int n)
{
    int i;
    for (i = 0; i < n; i++)
    {
        if (c[i].balance < 1000)
        {
            printf("Acc: %d, Name: %s, Bal: %.2f\n", c[i].acc_no, c[i].name, c[i].balance);
        }
    }
}

void transaction(struct customer *c, int n, int acc, float amount, int code)
{
    int i, found = 0;
    for (i = 0; i < n; i++)
    {
        if (c[i].acc_no == acc)
        {
            found = 1;
            if (code == 1) // Deposit
            {
                c[i].balance += amount;
                printf("Deposit successful. New Balance: %.2f\n", c[i].balance);
            }
            else if (code == 0) // Withdraw
            {
                if (c[i].balance - amount < 1000)
                {
                    printf("The balance is insufficient for the specified withdrawal (Must maintain min 1000).\n");
                }
                else
                {
                    c[i].balance -= amount;
                    printf("Withdrawal successful. New Balance: %.2f\n", c[i].balance);
                }
            }
            else
            {
                printf("Invalid transaction code.\n");
            }
            break;
        }
    }
    if (!found) printf("Account number not found.\n");
}