116 Programming and Data Structures
Explanation In the above-mentioned program the outer switch counts only the spaces in a given
text. For other spaces inner switch statement is used. The inner switch is for counting Is, Os, and
others. The string length is printed at the end of the program, which is the addition of all the counts.
5.10 THE switch () CASE AND NESTED IFS
switch () case
nested ifs
The switch () can only test for equality
i.e. only constant values are applicable.
The if can evaluate relational or logical
expressions.
No two case statements have identical
constants in the same switch.
Same conditions may be repeated for
number of times.
Character constants are automatically
converted to integers.
Character constants are automatically
converted to integers.
In sw itch () case statement nested if can
be used.
In nested if statement sw itch () case
can be used.
530 Write a program to convert integer to character using if condition.
nalnO
{
in t xi
clr«er() j
printf (Mn Enter a Number:);
scanf ("%d",Sac);
if(x='A')
printf (“%c",x);
}
OUTPUT;
Enter a Number: 65
A
Explanation In this program the variable 'x ' is declared as an integer variable. Its value is entered
through the keyboard. The ASCII value of the entered number is checked with the i f statement. If there
is a match the ASCII value is displayed.
531 Write a program to use nested if..else statements in swtichO statement. Also show the
effect of conversion of integer to character.
#indude<sbdio.h>
#lncluds<conio.h>
void maixvO
{
in t i ;
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.220.245.140