Unit 1 of 4 · B.Sc IT Sem 1

Unit 1: Algorithm development and C fundamentals

Programming in C notes · PTU syllabus (BSIT102/BSBC102)

3 min read7 topics10 exam questions
On this page
  1. Unit summary
  2. Steps in program development
  3. Algorithms and flowcharts
  4. Debugging, compilation and execution
  5. Keywords and identifiers
  6. Data types, constants and variables
  7. Operators and expressions
  8. Input/output and assignment statements
  9. Key terms
  10. Quick revision
  11. Important questions

Unit summary

Programming starts with a clear algorithm and the basic building blocks of the C language. This unit covers the steps in program development, flowcharts and algorithm development, debugging, compilation and execution, input/output and assignment statements, constants, variables, operators and expressions, keywords, data types and identifiers.

After this unit you can

  • Explain the steps in program development, algorithms and flowcharts
  • Explain debugging, compilation and execution of C programs
  • Use constants, variables, data types, keywords and identifiers
  • Write expressions with operators and I/O statements

PTU syllabus topics

  • Steps in program development
  • flowcharts
  • algorithm development
  • debugging
  • compilation and execution
  • I/O statements
  • assignment statements
  • constants
  • variables
  • operators and expressions
  • keywords
  • data types and identifiers
ProcessFrom source code to running program
  1. 1Write source code

    .c file

  2. 2Preprocessor

    Expands #include and #define

  3. 3Compiler

    Converts to object code

  4. 4Linker

    Adds library code, makes executable

  5. 5Loader

    Loads into memory and runs

1

Topic 1

Steps in program development

ProcessProgram development cycle
  1. 1

    Define the problem

  2. 2

    Analyse inputs, outputs and processing

  3. 3

    Design the algorithm and flowchart

  4. 4

    Code the program

  5. 5

    Compile and remove syntax errors

  6. 6

    Test and debug

  7. 7

    Document

  8. 8

    Maintain

2

Topic 2

Algorithms and flowcharts

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

Debugging, compilation and execution

ProcessFrom source code to execution
  1. 1

    Write source code (prog.c)

  2. 2

    Preprocessor

    Expands #include and #define

  3. 3

    Compiler

    Converts to object code; reports syntax errors

  4. 4

    Linker

    Joins object code with library functions to make an executable

  5. 5

    Loader

    Loads the program into memory

  6. 6

    Execution

    Runs and produces output

  • Errors: syntax errors (compiler), linker errors (missing functions), run-time errors (division by zero), logical errors (wrong output).
  • Debugging: reading error messages, printing intermediate values, dry runs with trace tables, using a debugger (gdb, IDE breakpoints).
  • Commands: gcc prog.c -o prog then ./prog.
4

Topic 4

Keywords and identifiers

  • 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 and expressions

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

Topic 7

Input/output and assignment statements

  • Assignment: variable = expression; compound forms +=, −=, *=, /=, %=.
  • Formatted I/O: printf and scanf with format specifiers %d, %f, %c, %s, %lf; unformatted I/O: getchar, putchar, gets (unsafe — use fgets), puts.
c#include <stdio.h>
int main(void) {
    int a, b;
    printf("Enter two numbers: ");
    scanf("%d %d", &a, &b);
    int sum = a + b;            /* assignment */
    printf("Sum = %d\n", sum);
    return 0;
}

Key terms

Algorithm
Finite step-by-step procedure to solve a problem
Flowchart
Diagram of an algorithm using standard symbols
Compiler
Translates source code into object code
Identifier
Name given to a variable or function
Logical error
Error giving wrong output without compiler messages

Quick revision

  • Program development steps; algorithm properties; flowchart symbols.
  • Preprocess → compile → link → load → execute; error types; debugging.
  • Character set, 32 keywords, identifier rules.
  • Data types, constants, variables; operators, precedence and expressions.
  • printf, scanf, getchar, putchar; assignment.

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.State the steps in program development.
  2. Q2.Name four flowchart symbols.
  3. Q3.Distinguish syntax and logical errors.
  4. Q4.What does the linker do?
  5. Q5.State the rules for naming identifiers.
  6. Q6.What is the difference between = and ==?

Long-answer questions

  1. Q1.Explain the steps in program development with algorithm and flowchart.
  2. Q2.Explain compilation, linking and execution of a C program and debugging.
  3. Q3.Explain data types, constants, variables, keywords and identifiers in C.
  4. Q4.Explain operators and expressions in C with examples.

Stuck on this unit?

Message SBS on WhatsApp for help with Programming in C, or to ask about studying B.Sc IT at Synetic.

WhatsApp us