Page 63 - Modular_V1.1_Flipbook
P. 63
In the preceding syntax, you can see that a label is used with the goto statement to specify the
location where the control of the program execution will be transferred. At some other part of
the program, the same label will be available with colon.
MORE SOLVED PROGRAMS
Program 9: To check whether the input number is even or odd using the goto statement.
#include<iostream.h>
#include<conio.h>
void main()
{
int num = 10;
if (num % 2 == 0)
goto even;
else
goto odd;
even: cout<<”Number is even”;
goto end;
odd: cout<<”Number is odd”;
end: getch();
}
Program 10: To find the sum of following series:
1+x+x^2/2!+x^3/3!+....x^n/(n+1)!
#include<iostream.h>
#include<conio.h>
void main()
{
float x, sum, p;
int i, n;
cout << “ Enter the value of x: “;
cin >> x;
cout << “ Enter number of terms: “;
cin >> n;
sum = 1;
p = 1;
for (i = 1; i < n; i++)
{
p = p * x / (float)i;
sum = sum + p;
}
Loops 61

