0% found this document useful (0 votes)
8 views3 pages

Programs Done On 08-02-2025

The document contains three C++ programs. The first program checks if a number is prime and prints its reverse if it is; the second checks if a number is a Disarium number; and the third forms a new number from the odd digits of the input number. Each program includes code snippets and explanations of their functionality.

Uploaded by

tapanvety
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Programs Done On 08-02-2025

The document contains three C++ programs. The first program checks if a number is prime and prints its reverse if it is; the second checks if a number is a Disarium number; and the third forms a new number from the odd digits of the input number. Each program includes code snippets and explanations of their functionality.

Uploaded by

tapanvety
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Programs done on 08-02-2025

1. WAP to enter a number if it is a prime number print its reverse number.

#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;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy