Asked by Jennifer
Write a C++ program to check whether a number divided by 2, [Hint: write a function to check remaider when 'n' is divided by 2]
Answers
Answered by
Trinity
I think that your question is to check whether a number can be divided by 2 or not.
To do this simply take that number and run it through a remainder operator. For example, n % 2. If n is 2 then the output will be 0 but if n is 3 then the output will be 1.
Using that logic, we can make a rough code like
if (n % 2 == 0) {
printf("n can be divided by 2);
}
else {
printf("n cannot be divided by 2);
}
you can finish this code up by assigning a value to n. Good luck
To do this simply take that number and run it through a remainder operator. For example, n % 2. If n is 2 then the output will be 0 but if n is 3 then the output will be 1.
Using that logic, we can make a rough code like
if (n % 2 == 0) {
printf("n can be divided by 2);
}
else {
printf("n cannot be divided by 2);
}
you can finish this code up by assigning a value to n. Good luck
There are no AI answers yet. The ability to request AI answers is coming soon!
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.