# Thread: Set intersection in C

1. ## Set intersection in C

I have a task for college and I have to write a code for an intersection of sets in C. I have written the code, and when I try to test the program with 9 previously defined tests, I pass 8 out of 9 of them. I get an error in one of the tests, where my condition actually coincide with previous condition. I have no idea how to fix this so I'm here asking y'all how can i fix this. Here is the code in pastebin, so you could see and try to help me.

Note: We didn't learn about arrays or lists, so I am not allowed to use that, and loops too...

"Unesite brojeve a, b, c, d" - means "Insert numbers a,b,c,d"
"Rezultantni interval je" - means "Final interval is"
"Skupovi se ne sijeku" - means "Sets do not intersect"

I hope that you can help me
Here is the code: https://pastebin.com/hBTxEQEv

2. What is the test that fails?

If you were not given the test values, then you should write your own 9 tests that try to replicate what your instructor is testing. Knowing what is the failing test will give you information on what you did wrong and some hint as to how to fix it.

3. The final condition definitely doesn't make sense.

4. I don't see any logic to ensure that the numbers are in proper order. That is, you never check if a < b, or c < d, prior to doing your other checks. This would be validation and your course may not be worried about it right now, but it's something to be aware of.

Next, consider what happens if some of the compared values are exactly equal to each other. Your relations all check for strict greater or strict less than. And in most cases that may be enough. But think through a case where values are equal.

Also, what happens if both ends of your intervals are the same number? That is, something like 1.0 1.0 for a and b. Will your code work?

5. You can rewrite any loop as a set of recursive calls. There's a school of thought that you should do that. However not normally in C, but in a so-called "functional" programming language. Scheme is an example.