Exp – 5
WAP to check a number is pallimdrome or not.
#include <iostream.h>
#include<conio.h>
int main()
int num, rev = 0, rem, num1;
cout << "Enter a number: ";
cin >> num;
num1 = num;
while (num != 0)
rem = num % 10;
rev = rev * 10 + rem;
num /= 10;
if (num1 == rev)
cout << num1 << " is a palindrome number." << endl;
else
cout << num1 << " is not a palindrome number." << endl;
getch();
return 0;
Output :
Enter a number : 121
is a palindrome number
Enter a number : 123
is not a palindrome number
Write a program to check a number is armstrong is or not
#include <iostream.h>
#include <math.h>
#include<conio.h>
int main()
int num, num1, rem, result = 0, n = 0;
cout << "Enter a number: ";
cin >> num;
num1 = num;
while (num1 != 0)
num1 /= 10;
n++;
num1 = num;
while (num1 != 0) {
rem = num1 % 10;
result += pow(rem, n);
num1 /= 10;
}
if (result == num)
cout << num << " is an Armstrong number." << endl;
else
cout << num << " is not an Armstrong number." << endl;
getch();
return 0;
Output :
Insert a number : 153
Is an Armstrong number
Insert a number : 123
is not an Armstrong number
Write a program to print fibonecci series
#include <iostream.h>
#include <conio.h>
int main()
int n, t1 = 0, t2 = 1, t3;
cout << "Enter the number of terms: ";
cin >> n;
cout << "Fibonacci Series: ";
for (int i = 1; i <= n; ++i)
cout << t1 << " ";
t3 = t1 + t2;
t1 = t2;
t2 = t3;
getch();
return 0;
Output :
Enter the number of terms: 4
0112
Write a program to print factorial of a number.
#include <iostream.h>
#include<conio.h>
int main()
int num , fact = 1;
cout << "Enter a positive integer: ";
cin >> num;
if (num < 0)
cout << "Factorial is not defined for negative numbers." << endl;
else
for (int i = 1; i <= num; ++i)
fact = fact * i;
cout << "Factorial of " << num << " = " << fact<< endl;
getch();
return 0;
WAP to print multiplication table of n.
#include<iostream.h>
int main()
int n;
cout<< "enter a number";
cin >> n;
for(int i = 1; i <= 10; i++)
cout << n << " * " << i << " = " << n * i << endl;
getch();
return 0;
}