Structural Programming
Structural Programming is a technique that divides a program into small modules (functions)
and follows a structured flow.
Key Features
• Uses sequence, selection, iteration
• Avoids excessive use of goto
• Divides program into functions
Control Structures
1. Sequence – Step by step execution
2. Selection – if-else, switch
3. Iteration – for, while, do-while
4. Example (C Program)
5. #include<stdio.h>
6. int main() {
7. int a = 5, b = 10;
8. if(a < b) {
9. printf("B is greater");
10. }
11. return 0;
12. }
Advantages
✔ Easy to debug
✔ Better readability
✔ Modular approach
Disadvantages
Difficult for large real-world systems
Recursive Programming
Recursive Programming is a technique where a function calls itself to solve a problem.
Two Important Parts
1. Base Case – Stopping condition
2. Recursive Case – Function calls itself
Example: Factorial using Recursion
#include<stdio.h>
int fact(int n) {
if(n == 0) // Base case
return 1;
else
return n * fact(n - 1); // Recursive call
}
int main() {
printf("%d", fact(5));
return 0;
}