Hello atifasr,
A few remarks about your code:
What do you think happens to your program if the input contains more than 100 numbers ?
Your variables size and i are effectively the same thing. They’re both initialized to 1, and incremented at the same time.
The variable ans is used uninitialized on the first iteration of the loop.
You’re checking if ans == 42 at the start of a loop that will be entered only if ans != 42. That condition in your if can never be true.
You are THEN storing the input into ans, and not checking if it is now == 42. When 42 is encountered, it is going to be put in your array, supposing less than 100 numbers have been read so far.
I suggest you think about what you want to do exactly and what the constraints are, sort everything out so that it makes sense, and then start typing code.