63 123
Assignments Done
99%
Successfully Done
In July 2018

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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

Assignment Expert
04.11.14, 14:00

Dear 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 Expert
04.11.14, 13:59

Dear Zoe,
You're welcome. We are glad to be helpful. 
If you liked our service please press like-button beside answer field. Thank you!

Zoe
04.11.14, 11:15

Thanks a lot..............it really helped!!

Zoe
04.11.14, 10:50

thanks a lot........it really helped!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions