-2
Question 1 - Consider the set X = {x Z : 1 x 32}. Implement a program in C that performs the following instructions.
- Create three integer-type vectors of size 12: vector 0[12], vector 1[12] and vector 2[12].
- Store the elements belonging to X in the vector that leave 0 when divided by 3.
- Store in vector 1 the elements belonging to X that leave rest 1 when divided by 3.
- Store in vector 2 the elements belonging to X that leave rest 2 when divided by 3.
- Print the elements contained in vector 0.
- Print the elements contained in vector 1.
- Print the elements contained in vector 2.
Could someone help me with this code?
This afternoon a friend asked me to help resolve an issue in college.
I love programming, however it is many years since I finished high school and I can’t remember how to solve sets anymore. The only thing I remember is my teacher writing vectors on the blackboard or drawing polka dots to see if there was an intersection between two or more sets.
The set X represents the integers between 1 and 32 inclusive, so just declare and initialize each vector with the respective values. The exercise does not ask you to do this dynamically, so you can analyze it at hand (there are no joint operations in the exercise). Then just make three repeat loops and display the values of the vectors.
– Woss
@Andersoncarloswoss This looks like a failure on the part of the teacher. That maybe I don’t give a damn if someone comes up with an answer like the one you suggest.
– bfavaretto
William, however, here on the site this type of question is considered very broad. Code requests from an enunciation only tend to be poorly viewed. I suggest you edit the question and include an attempt to solve it yourself.
– bfavaretto
Thanks @bfavaretto, I really found the question a little imprudent. Because my problem is that I do not know how to solve the mathematical problem. But thank you very much for the tip, and for the solution of the problem. Thank you.
– Guilherme Lima
Understood that the key is the module operator
%
? But note that the answer they gave you has a problem, it considers a set of 33 items (0 to 32) instead of 32 (1 to 32).– bfavaretto
Understand perfectly, had already used the operator before. And very well observed in fact the is starts at 0.
– Guilherme Lima