Programs
Programs
1. WAP to enter 5 numbers then check and print if the numbers are
Pronic number or not.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n,i=1,fl,j;
cout<<"Enter 5 numbers : ";
while(i<=5)
{
cin>>n;
j=1;
fl=0;
while(j<n)
{
if(j*(j+1)==n)
{
cout<<n<<" is a Pronic number"<<endl;
fl=1;
break;
}
j++;
}
if(fl==0)
cout<<n<<" is not a Pronic number"<<endl;
i++;
}
getch();
}
2. WAP to enter a number then check and print if it is an Odious or Evil
number.
#include <iostream.h>
#include <conio.h>
void main()
{
clrscr();
int n,r,c=0,n1;
cout<<"Enter a number : ";
cin>>n;
n1=n;
while(n1>0)
{
r=n1%2;
if(r==1)
c++;
n1/=2;
}
if(c%2==1)
cout<<"It is an Odious number";
else
cout<<"It is an Evil number";
getch();
}
3. WAP to enter a number (Decimal) then convert and print it in Binary.
#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{
clrscr();
int n,r,c=0,n1,b=0; //p=1;
cout<<"Enter a number : ";
cin>>n;
n1=n;
while(n1>0)
{
r=n1%2;
b=r*(int)pow(10,c)+b; //b=r*p+b;
c++; //p=p*10;
n1/=2;
}
cout<<"Binary equivalent : "<<b;
getch();
}