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)
Difficulty Intermediate (index: 4 / 10)

Concepts

Beta Feature

This concept detection system is still in beta and may occasionally show incorrect or incomplete results.

  • Array
  • Pointers
  • Iteration
  • Sorting (possible)
  • Recursion

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");
}

Explanation

Explain with AI

Copy the prompt below and paste it into any AI assistant.

    You are explaining a C programming code to a beginner.

    STRICT RULES:

    - Only use the given code. Do NOT assume anything not present.

    - Do NOT add extra examples.

    - Keep explanation clear and short.

    - If something is unclear, say "Not clear from code".

    - Follow the exact format below. Do NOT change headings.

    FORMAT:

    [START]

    ## What it does

    (Explain the overall purpose in 1-2 sentences)

    ## Step-by-step

    (Explain how the code works in steps, simple language)

    ## Key Concepts

    (List concepts like loop, condition, function, etc.)

    ## Notes

    (Mention any limitations, errors, or assumptions)

    [END]

    CODE (luc079.c):

    #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");
                    }

    ... (truncated for brevity)