Computer Science & C Programming


Simplifying code (2)

  1. Affectation with arithmetic operators can be simplifed with the following equivalences:

Thus:

int sum(int n) {
	int result = 0;
	for (int counter=1; counter<=n; counter++) result += counter;
	return result;
}

10 - 10