' Simple Spreadsheet — cell values with arithmetic display
#COMPILE EXE
#DIM ALL

FUNCTION PBMAIN() AS LONG
    LOCAL a1 AS LONG, b1 AS LONG, c1 AS LONG, d1 AS LONG
    LOCAL a2 AS LONG, b2 AS LONG, c2 AS LONG, d2 AS LONG
    LOCAL a3 AS LONG, b3 AS LONG, c3 AS LONG, d3 AS LONG
    LOCAL result AS LONG
    LOCAL i AS LONG

    PRINT "Simple Spreadsheet Demo"
    PRINT "======================"
    PRINT ""

    a1 = 10: b1 = 20: c1 = 30: d1 = 40
    a2 = 5:  b2 = 15: c2 = 25: d2 = 35
    a3 = 100: b3 = 200: c3 = 300: d3 = 400

    PRINT "Grid:"
    PRINT "       A    B    C    D"
    PRINT "  1   "; a1; "  "; b1; "  "; c1; "  "; d1
    PRINT "  2   "; a2; "  "; b2; "  "; c2; "  "; d2
    PRINT "  3   "; a3; "  "; b3; "  "; c3; "  "; d3
    PRINT ""

    PRINT "Formula calculations:"
    PRINT "  A1 + B1 = "; a1 + b1
    PRINT "  C2 - A2 = "; c2 - a2
    PRINT "  B3 * A1 = "; b3 * a1
    PRINT "  D1 / A2 = "; d1 / a2
    PRINT ""

    PRINT "Sum row 1: "; a1 + b1 + c1 + d1
    result = a1 + b1 + c1 + d1
    PRINT "  = "; result

    PRINT "Sum col A: "; a1 + a2 + a3
    result = a1 + a2 + a3
    PRINT "  = "; result

    PRINT ""
    PRINT "Cross calculations:"
    result = a1 + b2 + c3
    PRINT "  A1 + B2 + C3 = "; result

    result = (a1 + b1) * (a2 + b2) / a3
    PRINT "  (A1+B1)*(A2+B2)/A3 = "; result

    result = a1 * a2 + b1 * b2 + c1 * c2
    PRINT "  A1*A2 + B1*B2 + C1*C2 = "; result

    PRINT ""
    PRINT "Multiplication table (5x5):"
    FOR i = 1 TO 5
        PRINT "  "; i; " * 5 = "; i * 5
    NEXT i

    PRINT ""
    PRINT "Spreadsheet simulation complete."

    FUNCTION = 0
END FUNCTION
