OK, so let me do this as two parts -- great question! First, I'm assuming you mean (e.g.) for an input of 5, you want the average of 1, 2, 3, 4, 5. 1+2+3+4+5=15 / 5 = 3.

This is pretty straight forward to write:

int main() {

unsigned n, c;

double sum;

printf("What is the max number? ");

scanf("%d", &n);

for (c=1; c <= n; sum+=c++) ;

printf("average=%lf", sum / n);

return 0;

}

However, the real trick here is to realize you don't need to do a loop :) For the sequence 1,2,3,4,5

1+5 = 6 / 2 = 3

2+4 = 6 / 2 = 3

3 = 3 / 1 = 3

In other words, the average of a range of numbers from 1...N is (N+1) / 2. You can therefore re-write this as:

int main() {

unsigned n, c;

double sum;

printf("What is the max number? ");

scanf("%d", &n);

printf("average=%lf", ((double)(n+1)/2));

return 0;

}