i have managed to write a program that reads an arbitrary number of integers less than or equal to 20 and finds the sum and average. i am now trying to write a bubble sort to order the integers from least to greatest but i am having problems. this is the code i have so far.
if it works its suppose to do this.
3 2 1 *
Entered integer 0: was 3
Entered integer 1: was 2
Entered integer 2: was 1
The sum was 6
the average is: 2.000000
--------------
The sorted list is 0: 1
The sorted list is 1: 2
The sorted list is 2: 3
#include <stdio.h>
#define SIZE 20
int main(void)
{
int count = 0;
int array[SIZE];
int sum = 0;
int i = count;
while (scanf("%d", &array[count]) != 0 ){
printf("Entered Integer number %d: was %d\n", count, array[count]);
sum += array[count];
count++;
}
printf("The sum was %d\n", sum);
float average = (float)sum / count;
printf("The average is: %f\n", average);
int this, next, temp;
for ( this = 0; this < count ; this ++){
for ( next = this + 1; next < count ; next ++ ){
if ( array[this] > array[next] ){
temp = array[this] ;
array[this] = array[next] ;
array[next] = temp ;
}
}
}
printf("------------\n");
for(count = 0; count < i; count++);{
printf("%d\n", array[count]);
}
return 0;
}
it instead does this
3 2 1 *
Entered integer 0: 3
Entered integer 1: 2
Entered integer 2: 1
The sum was 6
The average is: 2.00000
-----------------
1
please help