can someone help to bubble sort this one, thank you
#include<iostream>
using namespace std;
int main ()
{
int sum=0;
int mean=0;
int median=0;
int mode=0;
int grades[10] = {71,82,83,83,95,96,67,78,89,90};
for (int i = 0; i < 10; ++i)
sum+=grades[i];
mean = sum/10;
cout<<"Mean:"<<mean<<endl;
{
int j=0;
for (int i = 0; i < 10; ++i)
{
for (j=0; j<i; ++i)
{
if (grades[i]>grades[j])
{
int temp=grades[i];
grades[i]=grades[j];
grades[j]=temp;
}
}
}
}
system("pause");
return 0;
}
@eLypots
In your for loop of j, you have ++i instead of ++j
You still need a for loop to print out grades after the sort.
@eLypots
Just before you finish the program, use a for loop
1 2 3 4
|
for (int x=0;x<10;x++)
{
cout << grades[x] << " "; // The " ", is to put a space between each number in the array
}
|
Last edited on