Step 1: Total pairs \((a,b)\) in a binary operation.
Binary operation \( *:S\times S \to S\).
There are \(n^2\) ordered pairs. Step 2: Condition for commutativity.
Commutative means:
\[
a*b=b*a
\]
So values for \((a,b)\) and \((b,a)\) are same. Step 3: Count independent pairs.
- Diagonal pairs: \((a,a)\): there are \(n\).
- Off-diagonal pairs: \((a,b)\) where \(a\neq b\): they occur in symmetric pairs.
Number of such unordered pairs:
\[
\binom{n}{2}=\frac{n(n-1)}{2}
\]
So independent positions:
\[
n+\frac{n(n-1)}{2}=\frac{n(n+1)}{2}
\] Step 4: Assign values from S.
Each independent position can take \(n\) values.
So total commutative operations:
\[
n^{\frac{n(n+1)}{2}}
\] Final Answer:
\[
\boxed{n^{\frac{n(n+1)}{2}}}
\]