Algorithms • Flowcharts • Decision-Making • Control Structures in C
An algorithm is a step-by-step procedure to solve a problem. It must be clear, finite, and effective.
A flowchart visually represents an algorithm using standard symbols. It helps you understand the logic step-by-step before actual coding.
Oval – Start / End
Parallelogram – Input / Output
Rectangle – Process / Calculation
Diamond – Decision
Arrow – Flow Direction
Text description of the logic:
Decision-making statements enable the program to choose different actions based on conditions.
if Statement
if (condition) {
// code to execute if true
}
if…else Statement
if (condition) {
// true code
} else {
// false code
}
if Statements
if (a > 0) {
if (a % 2 == 0) {
printf("Positive Even");
}
}
switch Statement
switch(choice) {
case 1: printf("Option 1"); break;
case 2: printf("Option 2"); break;
default: printf("Invalid");
}
Control structures determine the flow of execution—whether instructions repeat, skip, or choose a path.
// for loop example
for (int i = 1; i <= 5; i++) {
printf("%d ", i);
}
// while loop example
int i = 1;
while (i <= 5) {
printf("%d ", i);
i++;
}
// do-while example
int j = 1;
do {
printf("%d ", j);
j++;
} while (j <= 5);
// break example
for (int i = 1; i <= 10; i++) {
if (i == 5) break;
printf("%d ", i);
}
#includeint main() { int n; printf("Enter a number: "); scanf("%d", &n); if (n < 0) { printf("Negative number\n"); } else if (n == 0) { printf("Zero\n"); } else { printf("Positive number\n"); } printf("Counting from 1 to %d:\n", n); for (int i = 1; i <= n; i++) { printf("%d ", i); } return 0; }