# Answer to Question #47874 in C++ for Zoe

Question #47874

a simple c++ program that accepts positive integers and then displays a result whether the number is prime, odd, even or a perfect square

Expert's answer

//Connecting library

#include<iostream>

#include<math.h>

usingnamespace std;

boolisPrime(int a)

{

for(int i=1; i<a; i++)

{

if(a%i==0)

{

return false;

}

}

return true;

}

boolisOdd(int a)

{

if(a%2!=0)

{

return true;

}

else

{

return false;

}

}

boolisEven(int a)

{

if(a%2==0)

{

return true;

}

else

{

return false;

}

}

boolisSquare(int a)

{

double b =sqrt((double)a);

if(floor(b)==b)

{

return true;

}

else

{

return false;

}

}

//The main function

int main()

{

int a=0;

int sum=0;

while(1)

{

cout<<endl<<"Enter the number: ";

cin>>a;

if(a>0)

{

if(isPrime(a))

{

cout<<"This is Prime number!";

}

if(isOdd(a))

{

cout<<"This is Odd number!";

}

if(isEven(a))

{

cout<<"This is Even number!";

}

if(isSquare(a))

{

cout<<"This is Square number!";

}

}

else

{

cout<<"A negative number!!";

}

}

//system("pause");

return 0;

}

#include<iostream>

#include<math.h>

usingnamespace std;

boolisPrime(int a)

{

for(int i=1; i<a; i++)

{

if(a%i==0)

{

return false;

}

}

return true;

}

boolisOdd(int a)

{

if(a%2!=0)

{

return true;

}

else

{

return false;

}

}

boolisEven(int a)

{

if(a%2==0)

{

return true;

}

else

{

return false;

}

}

boolisSquare(int a)

{

double b =sqrt((double)a);

if(floor(b)==b)

{

return true;

}

else

{

return false;

}

}

//The main function

int main()

{

int a=0;

int sum=0;

while(1)

{

cout<<endl<<"Enter the number: ";

cin>>a;

if(a>0)

{

if(isPrime(a))

{

cout<<"This is Prime number!";

}

if(isOdd(a))

{

cout<<"This is Odd number!";

}

if(isEven(a))

{

cout<<"This is Even number!";

}

if(isSquare(a))

{

cout<<"This is Square number!";

}

}

else

{

cout<<"A negative number!!";

}

}

//system("pause");

return 0;

}

## Comments

Assignment Expert04.11.14, 14:00Dear Zoe,

You're welcome. We are glad to be helpful.

If you liked our service please press like-button beside answer field. Thank you!

Assignment Expert04.11.14, 13:59Dear Zoe,

You're welcome. We are glad to be helpful.

If you liked our service please press like-button beside answer field. Thank you!

Zoe04.11.14, 11:15Thanks a lot..............it really helped!!

Zoe04.11.14, 10:50thanks a lot........it really helped!

## Leave a comment