Programs Done On 08-02-2025
Programs Done On 08-02-2025
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr();
int n,i=1,c=0,t,r=0,d;
cout<<"Enter a number : ";
cin>>n;
t=n;
while(i<=n)
{
if(n%i==0)
c++;
i++;
}
if(c==2)
{
while(t>0)
{
d=t%10;
r=r*10+d;
t/=10;
}
cout<<n<<" is Prime and its reverse is : "<<r;
}
else
cout<<n<<" is not a Prime number";
return 0;
}
2. WAP to enter a number then check and print if it is a Disarium number.
135 11 + 32 + 53 =1+9+125=135
#include <iostream.h>
#include <conio.h>
#include <math.h>
int main()
{
clrscr();
int n,i,n1,c=0,s=0,d;
cout<<"Enter a number : ";
cin>>n;
n1=n;
while(n1>0)
{
c++;
n1/=10;
}
n1=n;
while(n1>0)
{
d=n1%10;
s=s+pow(d,c--);
n1/=10;
}
if(n==s)
cout<<n<<" is a Disarium number";
else
cout<<n<<" is not a Disarium number";
return 0;
}
3. WAP to enter a number then form a new number taking out all the odd
digits.
Input: 23687
Output:73 or 37
#include <iostream.h>
#include <conio.h>
int main()
{
clrscr();
int n,t,n1=0,d;
cout<<"Enter a number : ";
cin>>n;
t=n;
while(t>0)
{
d=t%10;
if(d%2==1)
n1=n1*10+d;
t/=10;
}
cout<<"The new number is : "<<n1;
return 0;
}
OR
#include <iostream.h>
#include <conio.h>
int main()
In this program odd digits are
{
clrscr(); arranged in order of their
int n,t,n1=0,d,c=0,p=1; appearance in the original number
cout<<"Enter a number : ";
cin>>n;
t=n;
while(t>0)
{
d=t%10;
if(d%2==1)
{
n1=d*p+n1; // n1=d*(int)pow(10,c++)+n1;
p=p*10;
}
t/=10;
}
cout<<"The new number is : "<<n1;
return 0;
}