• ¿Documento equivocado? Cámbialo gratis
  • Escrito por estudiantes que aprobaron
  • Inmediatamente disponible después del pago
  • Leer en línea o como PDF
Vender
¿Dónde estudias?
Tu idioma
Document preview thumbnail
Vista previa 2 fuera de 8 páginas
Notas de lectura

C Programming Comprehensive Lecture Notes: Decision Making, Iterative Constructs, Loop Control & Algorithmic Tracing

Document preview thumbnail
Vista previa 2 fuera de 8 páginas

Extensive university-grade C Programming Module 02 lecture notes for Computer Science students. Includes formal control flow theory, structured selection syntax, jump-table mechanics for switch statements, complete iteration anatomy, sentinel vs. counter-controlled loops, step-by-step variable trace tables, nested loop complexity analysis, and fully solved university examination programs.

Vista previa del contenido

LECTURE NOTES: CONTROL FLOW, ITERATION &
ALGORITHMIC TRACING
Course: CS-101 Fundamentals of Programming in C | Module 02: Comprehensive
Lecture & Class Notes




1. Foundations of Structured Control Flow
According to the Böhm–Jacopini Structured Program Theorem, any computable
algorithm can be expressed using three fundamental control structures: Sequence,
Selection, and Iteration.
1.1 Boolean Truth Representation in C
Historically, ANSI C89 lacked a dedicated boolean primitive. Consequently, all conditional
expressions evaluate to an integer of type int :
Logical False: Strictly integer zero ( 0 ), floating-point zero ( 0.0 ), or the null pointer
( NULL ).
Logical True: Any non-zero value (positive or negative, such as 1 , -5 , or 42 ).
Relational and logical operators ( == , != , < , && , || ) are guaranteed by the C
standard to yield strictly 1 or 0 .

2. Selection Statements & Branching Mechanics
2.1 Single-Alternative and Dual-Alternative Selection
[ Evaluate Condition ]
/
True / \ False
vv
±---------------+ ±---------------+
| True Branch | | False Branch |
| Statement(s) | | Statement(s) |
±---------------+ ±---------------+
\/
vv
[ Next Statement ]
Syntax & Block Scoping
if (condition_expression) {
// Compound statement block (executes if condition_expression != 0)
} else {

,// Alternative compound block (executes if condition_expression == 0)
}


Scope Rule (C99/C11): Variables declared inside an if or else compound block
possess block scope and automatic storage duration; their memory is reclaimed
immediately upon exiting the closing brace } .


2.2 Multi-Alternative Selection: The else-if Ladder
When testing mutually exclusive conditions sequentially, the else-if ladder guarantees
that once the first true condition is encountered, its associated block executes and all
remaining branches are bypassed:
#include <stdio.h>

int main(void) {
double units, bill;
printf(“Enter electricity units consumed: “);
scanf(”%lf”, &units);


if (units <= 100.0) {
bill = units * 1.50;
} else if (units <= 200.0) {
bill = (100.0 * 1.50) + ((units - 100.0) * 2.50);
} else if (units <= 300.0) {
bill = (100.0 * 1.50) + (100.0 * 2.50) + ((units - 200.0) * 4.00);
} else {
bill = (100.0 * 1.50) + (100.0 * 2.50) + (100.0 * 4.00) + ((units - 300.0) * 6.00);
}


printf("Total Payable Bill: $%.2lf\n", bill);
return 0;


}
2.3 Multi-Way Dispatch: The switch…case Statement
The switch statement evaluates an integral control expression once and transfers
control directly to the matching case constant label.
Formal Syntax Constraints
Control Expression: Must undergo integer promotion to int , long , char , or enum .
Floating-point types ( float , double ) and strings ( char* ) produce a compile-time error.
Case Labels: Each case label must be a unique compile-time constant expression
(e.g., case 10: or case ‘A’: ). Variable identifiers (e.g., case x: ) are illegal in standard C.

Información del documento

Subido en
25 de noviembre de 2026
Número de páginas
8
Escrito en
2026/2027
Tipo
Notas de lectura
Profesor(es)
General / standard curriculum
Contiene
For all classes
$7.99

¿Documento equivocado? Cámbialo gratis Dentro de los 14 días posteriores a la compra y antes de descargarlo, puedes elegir otro documento. Puedes gastar el importe de nuevo.
Escrito por estudiantes que aprobaron
Inmediatamente disponible después del pago
Leer en línea o como PDF

Vendido
0
Seguidores
0
Artículos
8
Última venta
-



Por qué los estudiantes eligen Stuvia

Creado por compañeros estudiantes, verificado por reseñas

Calidad en la que puedes confiar: escrito por estudiantes que aprobaron y evaluado por otros que han usado estos resúmenes.

¿No estás satisfecho? Elige otro documento

¡No te preocupes! Puedes elegir directamente otro documento que se ajuste mejor a lo que buscas.

Paga como quieras, empieza a estudiar al instante

Sin suscripción, sin compromisos. Paga como estés acostumbrado con tarjeta de crédito y descarga tu documento PDF inmediatamente.

Student with book image

“Comprado, descargado y aprobado. Así de fácil puede ser.”

Alisha Student

Preguntas frecuentes