0% found this document useful (0 votes)
42 views

Conditional Statements (Nested If-Else Statement)

This module discusses nested if-else conditional statements in C programming. It has two objectives: to teach students about conditional statements and how to apply nested if-else statements when creating programs. The document provides an example of a program that uses nested if-else statements to convert a grade percentage to a number and letter grade equivalent. It evaluates the conditions from top to bottom and executes the statement for the first true condition.

Uploaded by

Deonisis Versola
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
42 views

Conditional Statements (Nested If-Else Statement)

This module discusses nested if-else conditional statements in C programming. It has two objectives: to teach students about conditional statements and how to apply nested if-else statements when creating programs. The document provides an example of a program that uses nested if-else statements to convert a grade percentage to a number and letter grade equivalent. It evaluates the conditions from top to bottom and executes the statement for the first true condition.

Uploaded by

Deonisis Versola
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 2

MODULE 7: CONDITIONAL STATEMENTS (NESTED IF-ELSE STATEMENT)

Objectives:
At the end of the module the students should be able to
1. Acquire knowledge about conditional statements in Turbo C programming.
2. Apply properly the nested if-else statement in creating programs in C.

Duration: 2 hrs.

a. Nested if else
The conditions are evaluated from top downward. As soon as a true condition is found, the
statement associated with it is executed and the rest of the ladder is bypassed. If none of the
conditions are true, the final else is executed. The final else often acts as a default condition;
that is, if all other conditional tests fail, the last else statement is performed. If the final else is
not present, then no action takes place if all other conditions are false.

Syntax
if (condition)
<statement 1>;
else if (condition) <statement 2>;
.
.
else <statement N>;

Example Program [nested if else]


/*This program converts the grade in percentage to number and letter.*/
#include<stdio.h>
main()
{
int grade;
clrscr();
printf("Enter a grade in percentage:");
scanf("%d",&grade);
if ((grade>=97) && (grade<=99))
printf("Your number and letter equivalent:[1.00] [A]");
else if ((grade>=94) && (grade<=96))
printf("Your number and letter equivalent:[1.25] [A-]");
else if ((grade>=91) && (grade<=93))
printf("Your number and letter equivalent:[1.50] [B+]");
else if ((grade>=88) && (grade<=90))
printf("Your number and letter equivalent:[1.75] [B]");
else if ((grade>=85) && (grade<=87))
printf("Your number and letter equivalent:[2.00] [B-]");
else if ((grade>=80) && (grade<=84))
printf("Your number and letter equivalent:[2.50] [C+]");
else if ((grade>=75) && (grade<=79))
printf("Your number and letter equivalent:[3.00] [C]");
else if ((grade>=74) && (grade<=70))
printf("Your number and letter equivalent:[5.00] [F]");
else
printf("Out of Range");
getch();
}

You might also like