Page 70 - Modular_V2.0_C++_Flikpbook
P. 70
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;
clrscr();
cout<< "Enter a number: ";
cin>> num;
if(num % 2 == 0)
goto even;
else
DOSBox 0.74, Cpu speed: max 100% cycles,
goto odd;
Enter a number: 62
even: Number is even
cout<< "Number is even\n";
DOSBox 0.74, Cpu speed: max 100% cycles,
goto end;
Enter a number: 53
odd:
Number is odd
cout<< "Number is odd\n";
end:
getch();
}
Program 10: To find the sum of following series:
1+x+x^2/2!+x^3/3!+....x^n/n!
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
float x, sum, p;
int i, n;
cout<< "Enter the value of x: ";
cin>> x;
cout<< "Enter the number of terms: ";
cin>> n;
DOSBox 0.74, Cpu speed: max 100% cycles,
sum = 1;
Enter the value of x: 2
p = 1; Enter the number of terms: 5
The sum is: 7.266667
68
Touchpad MODULAR (Ver. 2.0)

