Computer Science & C Programming


Control structures (revised)

  1. The preceding loop do something while a condition is true and can be simplified by:
int sum(int n) {
	int result = 0, counter= 1;
	do {
	   result = result+counter;
	   counter= counter+1;
	} while (counter<=n);
	return result;
}

7 - 10