You have to capture the return value from rand(), and keep count of how many values captured from rand(), in the while loop, then after the loop, divide the total by the count to get the average.
For example:
Code:
value = rand();
total += value;
count++;
// Then after the loop ends:
average = (float) total / count;
Please use more descriptive names than a & b.
If total and value are ints, you have to cast one of the values to a float to avoid integer math that only results in a whole number result.
Please post your code in [ CODE ] blocks as specified in the Forum Rules FAQ above.