Unit 1: Logic development and C fundamentals
Problem Solving Techniques notes · PTU syllabus (UGSEC2501)
On this page
Unit summary
Before writing a program, a programmer must understand the problem and plan a solution. This unit teaches that planning — flowcharts, algorithms, pseudocode and decision tables — and then introduces the building blocks of the C language: its character set, keywords, data types, variables, constants, operators and expressions.
After this unit you can
- Analyse a problem and express its solution as an algorithm, flowchart or pseudocode
- Use decision tables and decision trees for multi-condition problems
- Explain C's character set, identifiers, keywords, data types, constants and variables
- Write expressions using C's operators and know their precedence
PTU syllabus topics
- Data representation
- flowcharts
- problem analysis
- decision trees/tables
- pseudocode and algorithms
- character set
- identifiers and keywords
- data types
- constants
- variables
- expressions
- statements
- symbolic constants
- arithmetic/unary/relational/logical/assignment/conditional operators
- library functions
- 1Understand the problem
Inputs, outputs and constraints
- 2Design the algorithm
Write steps in plain language or pseudocode
- 3Draw a flowchart
Visualise decisions and loops
- 4Code in C
Translate the design into statements
- 5Test and debug
Run with sample and edge-case inputs
Topic 1
Problem analysis and data representation
Solving a problem on a computer follows a fixed path.
- 1
Understand the problem
Inputs, outputs, conditions
- 2
Plan the solution
Algorithm or flowchart
- 3
Write the program
Code in C
- 4
Compile and debug
Fix syntax and logic errors
- 5
Test
Run with sample and edge inputs
- 6
Document and maintain
Computers store all data in binary (0 and 1). A bit is one binary digit; 8 bits make a byte. Characters are stored as numeric codes (ASCII: 'A' = 65, 'a' = 97, '0' = 48), integers in binary, and real numbers in floating-point form.
Topic 2
Algorithms, flowcharts and pseudocode
An algorithm is a finite, ordered set of clear steps that solves a problem. A good algorithm has input, output, definiteness, finiteness and effectiveness. A flowchart is a diagram of an algorithm using standard symbols.
| Symbol | Name | Used for |
|---|---|---|
| Oval | Terminal | Start and stop |
| Parallelogram | Input/Output | Read or print |
| Rectangle | Process | Calculation or assignment |
| Diamond | Decision | Yes/No condition |
| Arrow | Flow line | Direction of flow |
| Small circle | Connector | Joining parts of a chart |
Pseudocode is the algorithm written in plain, structured English that looks like code but follows no strict syntax.
Example
Algorithm to find the larger of two numbers: 1. Start. 2. Read A, B. 3. If A > B, print A; else print B. 4. Stop.
Topic 3
Decision tables and decision trees
When a problem has many conditions, a decision table lists the conditions, every combination of their values (rules) and the action for each. A decision tree shows the same logic as branches from left to right.
Example
Fee concession: if a student is a girl AND has above 80% marks, concession is 50%; if only one condition holds, 25%; otherwise none. A table of 4 rules (Y-Y, Y-N, N-Y, N-N) captures all cases.
Topic 4
C character set, identifiers and keywords
- Character set: letters (A–Z, a–z), digits (0–9), special symbols (+ − × / % ; { } etc.) and white space.
- Identifiers are names given to variables, functions and arrays. Rules: start with a letter or underscore, contain only letters, digits and underscores, are case-sensitive, and cannot be a keyword.
total_marksis valid;2sumandfloatare not. - Keywords are 32 reserved words with fixed meaning in C, such as
int,float,if,else,while,for,return,void,struct,switch.
Topic 5
Data types, constants and variables
| Data type | Typical size | Format specifier | Example |
|---|---|---|---|
| int | 2 or 4 bytes | %d | 25 |
| float | 4 bytes | %f | 3.14 |
| double | 8 bytes | %lf | 3.14159265 |
| char | 1 byte | %c | 'A' |
A variable is a named memory location whose value can change: int age = 18;. A constant is a fixed value: integer (25), real (3.5), character ('x') and string ("SBS"). A symbolic constant gives a constant a name: #define PI 3.14159.
Exam tip
Sizes of int depend on the compiler (2 bytes on old 16-bit compilers, 4 bytes on modern ones). Mention this in answers.
Topic 6
Operators, expressions and library functions
An expression combines operands and operators to produce a value.
Arithmetic
+ − × / %
a % b gives the remainder
Unary
++ −− − sizeof
i++ adds 1
Relational
< > <= >= == !=
a >= b gives 1 or 0
Logical
&& (AND), ! (NOT), OR
(a > 0) && (b > 0)
Assignment
= += −= ×= /=
x += 5 means x = x + 5
Conditional
? :
max = (a > b) ? a : b
- Precedence decides which operator is applied first (for example × and / before + and −); associativity decides the order among operators of equal precedence (mostly left to right).
- Library functions are ready-made functions in header files:
sqrt(),pow()in math.h;printf(),scanf()in stdio.h;strlen()in string.h.
c#include <stdio.h>
int main() {
int a = 10, b = 3;
printf("Sum = %d\n", a + b); /* 13 */
printf("Remainder = %d\n", a % b); /* 1 */
printf("Bigger = %d\n", (a > b) ? a : b);
return 0;
}Key terms
- Algorithm
- A finite sequence of clear steps to solve a problem
- Flowchart
- A diagram of an algorithm using standard symbols
- Pseudocode
- An algorithm written in structured plain English
- Identifier
- A user-defined name for a variable or function
- Keyword
- A reserved word with fixed meaning in C
- Precedence
- The order in which operators are evaluated
Quick revision
- Algorithm properties: input, output, definiteness, finiteness, effectiveness.
- Flowchart: oval = start/stop, parallelogram = I/O, rectangle = process, diamond = decision.
- Identifiers start with a letter or underscore; C has 32 keywords.
- int %d, float %f, double %lf, char %c.
- The conditional operator ?: is C's only ternary operator.
Important exam questions
Practice questions written to the PTU exam pattern for this unit's syllabus: short answers (Section A style) and long answers (Sections B and C style).
Short-answer questions
- Q1.Define an algorithm and list its characteristics.
- Q2.Draw any four flowchart symbols and state their use.
- Q3.What are the rules for naming identifiers in C?
- Q4.Differentiate between a variable and a constant.
- Q5.What is a symbolic constant?
- Q6.Explain the conditional operator with an example.
Long-answer questions
- Q1.Explain the steps of problem solving and draw a flowchart to find the largest of three numbers.
- Q2.What is a decision table? Prepare a decision table and decision tree for a problem of your choice.
- Q3.Explain the basic data types of C with their size and format specifiers.
- Q4.Explain the different types of operators in C with examples, including precedence and associativity.
Stuck on this unit?
Message SBS on WhatsApp for help with Problem Solving Techniques, or to ask about studying BCA at Synetic.
