assignment structured
assignment structured
DATE OF SUBMISSION:05-02-2025
GROUP 3 MEMBERS:
Allows the program to make decisions and execute different blocks of code based
on conditions.
Example:
if (condition) {
} else {
1. if Statement
The if statement evaluates a condition and executes a block of code only if the
condition is true.
Syntax:
if (condition) {
Example:
#include <stdio.h>
int main() {
int age;
return 0;
2. if-else Statement
The if-else statement provides two possible execution paths: one if the condition
is true and another if it is false.
Syntax:
if (condition) {
Example:
#include <stdio.h>
int main() {
int age;
else {
return 0;
if (condition1) {
} else if (condition2) {
} else {
Example:
#include <stdio.h>
int main() {
int age;
scanf("%d", &age);
} else {
return 0;
}
Example 2
#include <stdio.h>
int main() {
int age;
if (age >18){
else {
return 0;
4. Nested if Statement
Syntax:
if (condition1) {
if (condition2) {
Example:
#include <stdio.h>
int main() {
if (num > 0) {
if (num % 2 == 0) {
} else {
}
}
return 0;
#include <stdio.h>
int main() {
int age = 8;
} else {
} else {
}
return 0;
5. switch Statement
The switch statement is used when multiple conditions are based on a single
variable.
Syntax:
switch (expression) {
case value1:
break;
case value2:
break;
default:
Example:
#include <stdio.h>
int main() {
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");
break;
case 3:
printf("Wednesday\n");
break;
default:
printf("Invalid day\n");
return 0;
Example 2
#include <stdio.h>
int main() {
int day;
// Taking user input
scanf("%d", &day);
switch (day) {
case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
default:
return 0;
The default flow where statements execute one after another in the order they
appear.
#include <stdio.h>
int main() {
Example:
#include <stdio.h>
int main() {
printf("Step 1\n");
printf("Step 2\n");
return 0;
6. Program exits.
Example:
printf("%d\n", i);
Jump control structures in C allow the program to transfer control from one part
of the code to another. The main jump statements in C are:
#include <stdio.h>
int main(){
int i;
if (i == 3) {
break; // Exits the loop when i is 3
return 0;
ii)Continue – Skips the current iteration of a loop and moves to the next iteration.
Example
#include<stdio.h>
int main(){
int i;
if (i == 3) {
Example
#include <stdio.h>
int main() {
int i = 1;
start: // Label
printf("%d\n", i);
i++;
if (i <= 5) {
return 0;