Programming Fundamentals (C / BASIC)
Programming Fundamentals (C / BASIC)
This domain tests algorithm design, flowchart logic, data types, operators, control structures, arrays, functions and debugging in C and BASIC. You should be able to trace a short program and predict its output.
Core rules
- Sequence, selection and iteration are the three basic control structures. A flowchart uses standard symbols for start, input, process, decision and output.
- C is case-sensitive, statements end with semicolons, and blocks use braces. BASIC uses keywords such as PRINT, INPUT, IF, FOR and NEXT.
- Integer division in C discards the fractional part. Use floating-point types when fractions are needed.
- C arrays start at index 0; traditional BASIC arrays often start at 1 unless changed.
- Functions accept arguments and may return a value. Variables should be initialised before use.
Worked example
C fragment: int i, sum=0; for(i=1;i<=5;i++){sum=sum+i;} printf with %d prints sum. Trace: i=1 gives sum=1; i=2 gives 3; i=3 gives 6; i=4 gives 10; i=5 gives 15. Then i becomes 6, the condition fails, and the output is 15. In BASIC: sum=0: FOR i=1 TO 5: sum=sum+i: NEXT i: PRINT sum. The reasoning is the same accumulator pattern: each pass adds the current value of i to sum.
Traps
Do not confuse = assignment with == comparison in C. Missing braces can change loop scope. An off-by-one loop condition changes the total. Uninitialised variables contain unpredictable values. Integer division truncates, and array index limits are strict.