Unit 1 of 4 · BCA Sem 1

Unit 1: Logic development and C fundamentals

Problem Solving Techniques notes · PTU syllabus (UGSEC2501)

3 min read6 topics10 exam questions
On this page
  1. Unit summary
  2. Problem analysis and data representation
  3. Algorithms, flowcharts and pseudocode
  4. Decision tables and decision trees
  5. C character set, identifiers and keywords
  6. Data types, constants and variables
  7. Operators, expressions and library functions
  8. Key terms
  9. Quick revision
  10. Important questions

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
ProcessFrom problem to program
  1. 1Understand the problem

    Inputs, outputs and constraints

  2. 2Design the algorithm

    Write steps in plain language or pseudocode

  3. 3Draw a flowchart

    Visualise decisions and loops

  4. 4Code in C

    Translate the design into statements

  5. 5Test and debug

    Run with sample and edge-case inputs

1

Topic 1

Problem analysis and data representation

Solving a problem on a computer follows a fixed path.

ProcessSteps of program development
  1. 1

    Understand the problem

    Inputs, outputs, conditions

  2. 2

    Plan the solution

    Algorithm or flowchart

  3. 3

    Write the program

    Code in C

  4. 4

    Compile and debug

    Fix syntax and logic errors

  5. 5

    Test

    Run with sample and edge inputs

  6. 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.

2

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.

SymbolNameUsed for
OvalTerminalStart and stop
ParallelogramInput/OutputRead or print
RectangleProcessCalculation or assignment
DiamondDecisionYes/No condition
ArrowFlow lineDirection of flow
Small circleConnectorJoining 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.

3

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.

4

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_marks is valid; 2sum and float are not.
  • Keywords are 32 reserved words with fixed meaning in C, such as int, float, if, else, while, for, return, void, struct, switch.
5

Topic 5

Data types, constants and variables

Data typeTypical sizeFormat specifierExample
int2 or 4 bytes%d25
float4 bytes%f3.14
double8 bytes%lf3.14159265
char1 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.

6

Topic 6

Operators, expressions and library functions

An expression combines operands and operators to produce a value.

ComparisonOperators in C
Operators
Example

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

  1. Q1.Define an algorithm and list its characteristics.
  2. Q2.Draw any four flowchart symbols and state their use.
  3. Q3.What are the rules for naming identifiers in C?
  4. Q4.Differentiate between a variable and a constant.
  5. Q5.What is a symbolic constant?
  6. Q6.Explain the conditional operator with an example.

Long-answer questions

  1. Q1.Explain the steps of problem solving and draw a flowchart to find the largest of three numbers.
  2. Q2.What is a decision table? Prepare a decision table and decision tree for a problem of your choice.
  3. Q3.Explain the basic data types of C with their size and format specifiers.
  4. 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.

WhatsApp us