Structured Program Development
in C
– Structured programming uses clear control
structures.
– Reduces complexity and increases readability.
– Main structures: if, if…else, while, nested
statements.
IF Statement – Explanation
– Used to execute a block of code only when a
condition is TRUE.
– Syntax: if (condition) { statements; }
– Condition must return true (non-zero) or false (0).
IF Statement – Example Program
– #include <stdio.h>
– int main() {
– int age = 18;
– if(age >= 18) {
– printf("You are eligible to vote.\n");
– }
– return 0;
–}
IF…ELSE Statement – Explanation
– Executes one block if condition is TRUE and
another if FALSE.
– Useful for two-way decisions.
IF…ELSE – Example Program
– #include <stdio.h>
– int main() {
– int num = 7;
– if(num % 2 == 0) {
– printf("Even number\n");
– } else {
– printf("Odd number\n");
– }
– return 0;
–}
WHILE Loop – Explanation
– Repeats a block of code as long as the condition is
TRUE.
– Check happens BEFORE loop body executes.
– Used when number of iterations is unknown.
WHILE Loop – Example Program
– #include <stdio.h>
– int main() {
– int i = 1;
– while(i <= 5) {
– printf("%d ", i);
– i++;
– }
– return 0;
–}
Nested Control Statements –
Explanation
– Using one control statement inside another.
– Allows building complex logic (nested if, nested
loops).
Nested IF Example Program
– #include <stdio.h>
– int main() {
– int a = 10, b = 20;
– if(a > 5) {
– if(b > 15) {
– printf("Both conditions are true\n");
– }
– }
– return 0;
Nested WHILE Example Program
– #include <stdio.h>
– int main() {
– int i = 1;
– while(i <= 3) {
– int j = 1;
– while(j <= 3) {
– printf("%d,%d ", i, j);
– j++;
– }
– i++;
– printf("\n");
– }
– return 0;
– }