There are many correct answers. Here is one.
int r,k; r = 0; k = 1; while(k < n) { r = r + k; k = k + 1; }