Here is the question.
By using a single compound if statedment write a program to determine whether the user enters an odd positive number.
Im not to advanced in c++ but i do know i have to use the modulus operator.Im just not sure how to write it to figure if it is odd positive number.Also how would i test it by using relational operators?
thanks
Comments
: Here is the question.
:
: By using a single compound if statedment write a program to determine whether the user enters an odd positive number.
:
: Im not to advanced in c++ but i do know i have to use the modulus operator.Im just not sure how to write it to figure if it is odd positive number.Also how would i test it by using relational operators?
:
: thanks
:
X % 2 returns 0 if X is an even number. So just put an if statement around that and you have the answer to half your question. The other half is testing if X > 0.
:
: By using a single compound if statedment write a program to determine whether the user enters an odd positive number.
:
: Im not to advanced in c++ but i do know i have to use the modulus operator.Im just not sure how to write it to figure if it is odd positive number.Also how would i test it by using relational operators?
:
: thanks
:
You can write if((x%2)==0) cout<<"even"; //assumed x as a value
else cout<<"odd":
as x%2 returns remainder of number of x divided by 2
& if rem=0 it means it is even as for even/2 rem=0
if rem !=0 it means it is odd as for odd/2 rem !=0
you can also write
if((x=getch())%2)==0) cout<<"even";//include conio.h
else cout<<"odd"; // for getch()
above is if u want i/p in same expression.
:
: You r welcome