Page 73 - Modular_V2.0_C++_Flikpbook
P. 73
cout<< n << " is a Palindrome Number.";
}
else
{
cout<< n << " is not a Palindrome Number.";
}
getch();
}
Program 14: To calculate the Factorial of the input number.
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i;
float num;
double fact = 1; DOSBox 0.74, Cpu speed: max 100% cycles,
cout<< "Enter a number: "; Enter a number: 5
cin>> num; The factorial of 5 is 120
i = 1;
while(i <= num)
{
fact = fact * i;
i++;
}
cout<<"The factorial of "<< num<<" is "<<(double)fact;
getch();
}
Recap
The statements that are used to repeat a set of instructions are called iterative or looping
statements.
The for loop executes a simple or compound statements for a fixed number of times or until a
condition becomes false.
C++ allows you to combine two expressions using the comma operator.
The while loop executes a set of statements repeatedly until a certain condition is met.
The do-while loop is similar to the while loop.
If a loop executes inside another loop, it is known as nested loop.
The loop that never ends is called infinite loop.
Jump statements in C++ (break, continue, goto, return) control program flow by exiting loops,
skipping iterations, jumping to labels, or returning from functions.
71
Loops

