Write a main function that allows the user to insert a number and allows him to test the number where the number is;
1.+ve,-ve.
2.iteger,rational
3.even or odd
4.for all of theabove.
Use an if statement to determine what the user want to do.
what do you want todo.
1.check sign of the number .
2.check rationality .
3.check for allthe above.
1
Expert's answer
2011-06-10T07:54:02-0400
#include <iostream> #include <math.h> using namespace std;
// Function definitions void CheckSign (float num)& {
if (num > 0) { & cout<< "\nGiven number is POSITIVE.\n"; } else { & cout<< "\nGiven number is NEGATIVE.\n"; } }
void CheckRationality (float num) { if ((num - floor(num)) == 0)& // Getting fractional part of the number { & cout<< "\nGiven number is INTEGER\n"; } else { & cout<< "\nGiven number is RATIONAL\n"; } }
void CheckEven (float num) { int whole = (int)floor (num);& // Getting whole part of the number float frac = num - floor (num); // Getting fractional part of the number
if (((whole % 2)==0) && (frac == 0)) { & cout<< "\nGiven number is EVEN.\n"; } else { & cout<< "\nGiven number is ODD.\n"; } }
Comments
You are always welcome.
thanks alot.
Leave a comment