Program wyświetla 10 nieposortowanych elementów tablicy, po czym sortuje je metodą bąbelkową (parami) i wyświetla uporządkowaną tablicę.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//by Michuu^^
#include <iostream>
#include <cstring>
using namespace std;

int main()
{
int tab[10]={5,7,3,0,4,9,8,1,2,6};
int pom;
int zm=1;
for (int i=0; i<=9; i++)
{
cout<<"tab["<<i<<"] = "<<tab[i]<<endl;
}

system("pause");

while (zm==1)
{
zm=0;
for (int i=0; i<=8; i++)
{
if (tab[i]>tab[i+1])
{
pom=tab[i];
tab[i]=tab[i+1];
tab[i+1]=pom;
zm=1;
}
}
}

for (int i=0; i<=9; i++)
{
cout<<"tab["<<i<<"] = "<<tab[i]<<endl;
}

system("pause");
return 0;
}
C