int sumAllNumbersSmallerThanN(int n){
int sum=0;
int i;
for(i=1; i<n; i++){
sum += i;
}
return sum;
}
We simply declared a variable, sum, that will store the result, and set it to zero. Then, we loop all numbers from 1 to n-1, and we sum all these numbers to our sum. When the counter reaches n, the loop stops, and we will have added all numbers from 1 to n-1 in the variable sum.