98 Programming and Data Structures
5.6 THE continue STATEMENT
The continue statement is exactly opposite tobreak. The continue statement is used for continuing
next iteration of loop statements. When it occurs in the loop it does not terminate, but it skips the
statements after this statement. It is useful when we want to continue the program without executing
any part of the program.
5.7 THE goto STATEMENT
This statement dose not require any condition. This statement passes control anywhere in the program
i.e. control is transferred to another part of the program without testing any condition. The user has
to define
goto statement as follows.
goto label;
Where, the label name must start with any character.
Where label is the position where the control is to be transferred. Few examples are described for
the sake of understanding.
5.17 Write a program to delect the entered number as to whether it is even or odd. Use goto
statement
# include <atdio.h>
# include <eonio«h>
# include <stdlib.h>
void main()
{
int x;
clrscr ();
printf ("Enter a Number
scanf ("%d",6oc);
if (x% 2~0)
goto even;
else
goto odd;
even:
printf (" %d is Even Number/');
return;
odd:
printf (" %d is Odd Number/');
I
OUTPUT;
Enter a Number : 5
5 is Odd Number.
Decision Statements 99
Explanation In the above program a number is entered. The number is checked for even or odd with
modules division operator. When the number is even, the goto s tatement transfers the control to the
label even. Similarly when the number is odd thegoto statement transfers the control to the label odd
and respective message will be displayed.
5.18 Write a program to calculate telephone bill. Transfer controls at'different places according
to number of calls and calculate the total charges. Follow rates as per given in the table.
Telephone Call Rate in Rs.
<100 No Charges
>99 & <200 1
>199 & <300 2
>299 3
# include <stdio.h>
# include <conio.h>
void mainO
{
int nc;
clrscr();
printf (" Enter Number of Calls : ");
scanf ("%d",&nc);
if (nc<100)
goto free;
else if (nc>99 && nc<200)
goto chargel;
else if (nc>199 && nc<300)
goto charge2;
else
goto charge3;
fr e e :
printf (" No charges/');
return;
chargel:
printf ("n Total Charges : %d Rs.",nc*l);
return;
charge2:
printf (" Total Charges ;% d Rs.",nc*2);
return;
charge3:
printf (" Total Charges : %d Rs.",nc*3);
100 Programming and Data Structures
OUTPUT
Enter Number of Calls : 500
Total Charges: 1500 Rs.
Explanation The execution of the above program is same as the previous one. The difference is
that in this program control is transferred to various labels.
5.19 Write a program to check that the entered year is a leap year or not. Use goto statement
# in clu d e < std io.h>
#in clude < conio.h>
vo id mainO
{
in t le a p ;
clrecr();
printf ("Enter Year : ");
scanf ("%d",&cleap);
if(leap% 4~0)
goto leap;
else
goto noleap;
leap:
printf ("\%d is a leap year");
return;
noleap:
printf ("\%d is not a leap year");
J
Q .inrU T ;
Enter Year : 2000
2000 is a leap year.
Explanation Leap year comes in every four years. Hence, the entered year is divided using modulus
division operator by 4.1f the remainder is zero, it means that the year is a leap year.
..................Content has been hidden....................

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