Check the return value. If it's true for even, then it's not odd. In other words, basic logic.
Quzah.
Check the return value. If it's true for even, then it's not odd. In other words, basic logic.
Quzah.
Hope is the first step on the road to disappointment.
Are you saying I should put in an if statement? And which "return" are you wanting me to look at?
Explain to me exactly what this code does, segment by segment. If you can, then explain to me why it is you can't figure out how to tell if something is odd.Code:int even(int n) // return sum from 1 to n { return ( n % 2 == 0 ); }
Quzah.
Hope is the first step on the road to disappointment.
Ok, all that is doing is determining what the remainder is and printing it out. And the reason it is not printing "10 is even" is because I have not told it how to print out even.
Ok, I put in an if statement but it is working but putting out an odd answer.
it is saying:
10 is 4even
11 is 5odd
Code:#include <stdio.h> int is_even(int n) // return sum from 1 to n { if(n % 2 == 0) printf("odd\n"); else printf("even\n"); } int main (void) { int i, sum; for (i = 10; i <= 20 ; i++) { sum = is_even(i); printf("%d is %d", i, sum); } return 0; }
How would I use my function then?
How can you not be understanding this already? Check to see if mod-2 is 1. If it is ... ta dah ... it's ODD! Otherwise it's even! Now how can that possibly still confuse you?
Quzah.
Hope is the first step on the road to disappointment.
Yes, I understand
This is what I dont understand
What is the 4 in front of even and the 5 in front of odd?Code:10 is 4even 11 is 5odd
Whoa horsey!!! Stop. Calm down. Now, here is what you need to do. WITHOUT WRITING ANY CODE tell us what you need to do and how you plan to do it. Programming is not about the language you are using. Who cares that you are doing this in C? Do you even know how to get this answer? What would you do if I asked you to PROVE that each number from 10 to 20 was odd or even? How would you do that? Write it down, post it here and let us see that you know what you are doing FIRST. Then, we can help you get your thoughts to code.
Currently, I don't think you have a handle on the problem.
your almost there actually, with your permission i can show you the code if you want to
understand the logic