[go: up one dir, main page]

0% found this document useful (0 votes)
10 views10 pages

Conditional Program

The lab report by Krishal Upreti focuses on C programming, specifically on conditional statements such as if, else, and switch. It outlines objectives, theoretical background, and practical applications of these constructs, emphasizing their importance in decision-making within programs. The report concludes with a reflection on the skills gained and resources used for learning.

Uploaded by

LIGHTNING GAMERZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views10 pages

Conditional Program

The lab report by Krishal Upreti focuses on C programming, specifically on conditional statements such as if, else, and switch. It outlines objectives, theoretical background, and practical applications of these constructs, emphasizing their importance in decision-making within programs. The report concludes with a reflection on the skills gained and resources used for learning.

Uploaded by

LIGHTNING GAMERZ
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

TRINITY INTERNATIONAL SS & COLLEGE

KATHMANDU, NEPAL
2024

Lab Report on C-Programming (conditional)


(Computer Science)

Submitted By: Submitted To:


Name: Krishal Upreti Sanjay Phuyal

Grade: Eleven Department of Computer

Date: 2081/10/14
Student ID: 32015
TRINITY INTERNATIONAL SS & COLLEGE
KATHMANDU, NEPAL
2024

Lab Sheet #2
(C-Program)

Lab Date: - 2081/10/28


Submission Date: - 2081/11/05

Internal Signature External Signature


ACKNOWLEDGEMENT

This practical on C programming was a great challenge but I would like to express
my heartfelt thanks to all the respected people on this useful.
First and foremost, I would like to thank Sanjay Phuyal Sir, my computer science
teacher who helped me gain knowledge on this topic throughout this practical. His
expert advice and insights were crucial in helping me understand the features and
functions of C program It. I would also like the computer science department to
provide the needed equipment in this practical class and a conducive learning
environment that facilitates the successful completion of this useful.
I am also thankful to my friends: Nischal Tamang, Buwan Khati, Anurag Aryal,
and Rohit Rauniyar for providing me the support and ideas on this practical and
my family to give me the moral support needed during this practical.

Finally, I am grateful to C++ for developing such versatile and user-friendly


software that has revolutionized programming

Thank you all for your support and assistance

Krishal Upreti
2081/11/05
Objectives

 Learned how to make decisions in programs using if, else, and else if to
control the flow based on conditions.
 Explored the concept of nesting if statements within each other to handle
more complex decision-making scenarios.
 Gained proficiency in using the switch statement to evaluate a variable
against multiple values and execute corresponding blocks of code.
 Learned how conditional statements help control the flow of the program.
 Recognized that switch statements can often simplify code that would
otherwise require multiple if statements, improving readability and
maintainability.
 Understood how nested if statements can be used for more complex logic.
 Practiced using logical operators (&&, ||) with conditional statements to
evaluate multiple conditions simultaneously.
 Learned to handle situations where none of the specified conditions are met,
by using else or the default case in a switch statement.
Theoretical Background:
Programming constructs are the fundamental building blocks of any software
application. These constructs include variables, data types, loops, functions, and
control structures. Control structures, in particular, guide the flow of program
execution and are essential for decision-making processes.

Conditional Statements:

Conditional statements allow programs to make decisions based on specific


conditions. These statements execute different blocks of code depending on
whether a condition is true or false. The primary types of conditional statements
include:

 if statement: Executes a block of code if the condition is true.

Syntax:-

if (condition) {

// Code to execute if the condition is true

 if-else statement: Executes one block if the condition is true and another if
it is false.

Syntax:-

if (condition) {

// Code to execute if the condition is true

} else {

// Code to execute if the condition is false

}
 if-else-if ladder: Evaluates multiple conditions in sequence, executing the
block of the first true condition.

Syntax:-

if (condition1) {

// Code to execute if condition1 is true

} else if (condition2) {

// Code to execute if condition2 is true

} else {

// Code to execute if none of the conditions are true

}
Nested if Statements:

Nested if statements involve placing one if or if-else statement inside another. This
structure allows the program to evaluate conditions within conditions, providing
more granular control over the program's logic. It is particularly useful for complex
decision-making scenarios.

Syntax:-

if (condition1) {

// code to execute if condition1 is true

if (condition2) {

// code to execute if condition2 is true

} else {

// code to execute if condition2 is false

} else {

// code to execute if condition1 is false

}
Switch Statement:

The switch statement offers a more readable and efficient alternative to long if-
else-if ladders when a single variable is evaluated against multiple discrete values.
The switch structure includes:

Syntax:-

switch (expression) {

case value1:

// code to execute if expression == value1

break;

case value2:

// code to execute if expression == value2

break;

case value3:

// code to execute if expression == value3

break;

default:

// code to execute if no case matches

}
Conclusion:
In conclusion, mastering conditional statements like if, else, and switch is essential
for controlling the flow of a program based on specific conditions. Through the
study of nested if statements, I learned to handle more complex decision-making
scenarios, while the switch statement enabled me to simplify code that would
otherwise involve multiple if conditions. I gained the ability to evaluate multiple
conditions at once and create more efficient and readable code. Additionally,
understanding error handling with else and default ensures that my programs can
handle unexpected situations gracefully. These skills are fundamental for writing
clear, logical, and well-structured programs.
Reference

 Wikipedia:-Theory on programming construct C


Retrieved from:-https://wikipedia.org

 W3 school:-Programs of C programs and the concept


Retrieved from:-https://www.w3school.com

 Youtube:- Program questions


Channel:-W3 school
Retrived from:-https://www.youtube.com/watch?v=YnbODU_E_Ic

You might also like