Opis forum
#include<iostream.h>
#include<conio.h>
#include<math.h>
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
typedef int TYP;
main()
{
int i,j;
int a[20];
TYP tmp;
bool change;
randomize();
for (i=0; i<20; i++)
{ a[i]=rand()%20;
cout<<a[i]<<endl;
}
for (i=0; i<20; i++)
{
change=false;
for (j=0; j<20-i; j++)
if (a[j+1] < a[j]) //porównanie s±si±dów
{
tmp = a[j];
a[j] = a[j+1];
a[j+1] = tmp; //wypchanie b±belka
change=true;
}
if(!change) break; // nie dokonano zmian - koniec!
}
cout<<"oto ciag posortowany:"<<endl;
for (i=0; i<20; i++)
cout<<a[i]<<endl;
getch();
}
Offline