2014-10-15T14:45:14-04:00
a simple c++ program that accepts positive integers and then displays a result whether the number is prime, odd, even or a perfect square
1
2014-11-03T13:21:26-0500
//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 !
Learn more about our help with Assignments:
C++
Comments
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!
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!
Thanks a lot..............it really helped!!
thanks a lot........it really helped!