(N/A) proton has three quarks. Let there be $n$ up quarks in a proton,each having a charge of $+(2/3)e$.
Charge due to $n$ up quarks $= (2/3)e \cdot n$.
Number of down quarks in a proton $= 3-n$.
Each down quark has a charge of $-(1/3)e$.
Charge due to $(3-n)$ down quarks $= -(1/3)e \cdot (3-n)$.
Total charge on a proton $= +e$.
Therefore,$e = (2/3)en - (1/3)e(3-n)$.
$e = (2/3)en - e + (1/3)en$.
$2e = (3/3)en = en$.
Thus,$n = 2$.
Number of up quarks $= 2$,number of down quarks $= 3-2 = 1$. So,a proton is $uud$.
$A$ neutron has three quarks. Let there be $n$ up quarks in a neutron.
Charge due to $n$ up quarks $= (2/3)e \cdot n$.
Number of down quarks $= 3-n$,each with charge $-(1/3)e$.
Charge due to $(3-n)$ down quarks $= -(1/3)e \cdot (3-n)$.
Total charge on a neutron $= 0$.
Therefore,$0 = (2/3)en - (1/3)e(3-n)$.
$0 = (2/3)en - e + (1/3)en$.
$e = en$.
Thus,$n = 1$.
Number of up quarks $= 1$,number of down quarks $= 3-1 = 2$. So,a neutron is $udd$.