Question involving functions and permutations If $A=\{1,2,3,4\},B=\{a,b,c\}$, how many functions $A\to B$ are not onto? 
My Try: so one element in $B$ shouldn't have a preimage in A so one element is excluded(for convenience) so for $4$ elements in $A$ there are $2$ in B hence total ways are $16$ then $2$ elements in $B$ don't have a pre image so $2^3$ ways. Thus total ways are $16+8=24$ . So this can be done for all $3$ elements. Hence total ways are $72$ but answer given is $45$

You overcounted the "one element excluded" mappings
(assuming they were supposed to be "exactly one element excluded").
Yes, there are $16$ ways to map $A$ onto the two remaining elements of $B$
after one element of $B$ is excluded, but if you exclude $a$ (for example),
then two of the mappings you produce in this way are the one that
maps everything to $b$ and the one that maps everything to $c$.
So if you take your $16$ mappings and multiply by $3$, you have not only
already counted all the mappings that exclude two elements of $B$,
you have counted each of those mappings twice.
So the Inclusion-Exclusion Principle applies, and rather than add
the "two elements excluded" mappings, you should subtract them
from the total.
Moreover, there are not $2^3$ ways to map the elements of $A$ if
two elements of $B$ are excluded; there is only one way:
all elements of $A$ onto the one remaining element of $B$.
But there are three different elements of $B$ that might be the
one remaining, so there are a total of $3$ mappings excluding two elements.
In conclusion,
$$ 48 - 3 = 45 $$
is the correct answer.
An alternative is to remove the "only one element of $B$" mappings from
the "one element excluded" mappings, so instead of $16$ mappings,
you have only the $14$ mappings that actually use both remaining
elements of $B$.
Then you can compute the total number of mappings as
$$ (14 \cdot 3) + 3 = 42 + 3 = 45. $$
