UNIT -1 EL
UNIT -1 EL
Experiential Learning
In C, decision-making statements such as `if`, `if-else`, `nested if-else`, and `switch-case` are
used to control the flow of the program based on different conditions. Below are examples of
decision-making statements with practical applications in C.
```c
#include <stdio.h>
int main() {
int grade = 85;
return 0;
}
```
```c
#include <stdio.h>
int main() {
int attendance_percentage = 75;
return 0;
}
```
int main() {
char username[20] = "student123";
char password[20] = "password456";
if (strcmp(username, "student123") == 0) {
if (strcmp(password, "password456") == 0) {
printf("Access granted\n");
} else {
printf("Invalid password\n");
}
} else {
printf("Invalid username\n");
}
return 0;
}
```
**Application**: This checks both username and password for access control.
```c
#include <stdio.h>
int main() {
float gpa = 3.4;
return 0;
}
```
**Application**: This categorizes students based on their GPA into different academic
standings.
int main() {
int course_code = 101;
switch(course_code) {
case 101:
printf("Registered for: Introduction to Computer Science\n");
break;
case 201:
printf("Registered for: Calculus II\n");
break;
case 301:
printf("Registered for: Shakespearean Literature\n");
break;
case 202:
printf("Registered for: Genetics\n");
break;
default:
printf("Course not found\n");
break;
}
return 0;
}
```
**Application**: This uses a `switch-case` statement to register a student for a course based
on the course code.
```c
#include <stdio.h>
int main() {
int attendance = 80;
char *eligibility = (attendance >= 75) ? "Eligible" : "Not Eligible";
printf("%s\n", eligibility);
return 0;
}
```
**Application**: This compactly checks if a student is eligible to sit for exams based on
attendance.
int main() {
int grades[] = {85, 92, 78, 64, 89};
int updated_grades[5];
int i;
return 0;
}
```
**Application**: This loop iterates through a list of grades and applies a 5-point boost to any
grade below 70.
```c
#include <stdio.h>
int main() {
int grade = 85;
int attendance = 80;
printf("%s\n", performance_analysis(grade, attendance));
return 0;
}
```
### **9. `if` Statement with Logical Operators: Course Eligibility Check**
```c
#include <stdio.h>
int main() {
int math_grade = 85;
int science_grade = 90;
return 0;
}
```
**Application**: This checks whether a student’s grades in both Math and Science meet the
criteria for advanced course enrollment.
```c
#include <stdio.h>
int main() {
float gpa = 3.8;
int extra_curricular_activities = 1; // 1 means true, 0 means false
int volunteer_hours = 50;
return 0;
}
```
### **Conclusion**
These examples demonstrate how decision-making statements can be applied in various
practical applications using C. Whether managing grades, checking eligibility, or controlling
access, these statements are fundamental in writing programs that can make decisions and
react accordingly.