- 2071 Chaitra · 2 marks
Nested if with flowchart
Short answer
A nested if is an if statement placed inside another if or else. The inner condition is evaluated only when the outer condition is true. The flowchart branches from condition1: if true, evaluate condition2, else execute the outer else block.
Illustrate nested IF statement with its flowchart.
A nested if is an if statement placed inside another if or else. The inner condition is checked only when the outer condition is satisfied.
Syntax:
if (condition1)
{
if (condition2)
statement A;
else
statement B;
}
else
statement C;
Flowchart:
< condition1 ? >
True | | False
< condition2 ? > [ C ]
True | | False |
[ A ] [ B ] |
+-----+---------+
|
next statement
Example (largest of three):
#include <stdio.h>
int main(void)
{
int a = 15, b = 9, c = 22;
if (a > b)
{
if (a > c)
printf("%d is largest\n", a);
else
printf("%d is largest\n", c);
}
else
{
if (b > c)
printf("%d is largest\n", b);
else
printf("%d is largest\n", c);
}
return 0;
}
Output:
22 is largest
✓ Answer checked by Claude Opus 5.5 (high effort)
Related questions
- Compare switch and if-else-if ladder · Computer Programming, chapter 5 · asked 2×
- Conditional operator vs if-else; digit sum · Computer Programming, chapter 5
- Converse, inverse, contrapositive of prime statement · Discrete Structure, chapter 1 · asked 2×
- Converse etc. of temple statement · Discrete Structure, chapter 1
- Contrapositive and inverse: snow statement · Discrete Structure, chapter 1
- Euler's theorem statement with sin u example · Mathematics, chapter 1 · asked 3×