/* massiv elementlarini o'sib
borish tartibida saralash */
#include
using namespace std;
int main()
{
/*massivni initsializatsiyalash*/
int y[8]={44,55,12,42,94,18,06,67};
int L,i,j,n;
/* n-massiv elementlari soni */
cout<<"n=";
cin>>n;
cout<
/* dastlabki massiv elementlarini
ekranga chiqarish */
cout<<"dastlabki massiv";
cout<
cout<
for(int i=0; i
{
cout<<"y["<
cout<
}
cout<
/* massiv elementlarini saralashning
boshlanishi
i-bu massiv elementlari bo'yicha
o'tishning tartib raqami */
for(int i=0; i
{
/* j-bu massiv elementlari bo'yicha
sikl parametri */
for(int j=(n-1); j>0; j--)
{
if(y[j]
{
/* y[j-1] va y[j] elementlar
o'rinlarini almashtirish */
L=y[j-1];
y[j-1]=y[j];
y[j]=L;
}
}
}
cout<
cout<
/* saralangan massiv elementlarini
ekranga chiqarish */
cout<<"saralangan massiv";
cout<
cout<
for(int i=0; i
{
cout<<"y["<
cout<
}
cout<
system("pause");
return 0;
}
Dastur bajarilishi natijalari
n=8
dastlabki massiv
y[0]=44
y[1]=55
y[2]=12
y[3]=42
y[4]=94
y[5]=18
y[6]=6
y[7]=67
saralangan massiv
y[0]=6
y[1]=12
y[2]=18
y[3]=42
y[4]=44
y[5]=55
y[6]=67
y[7]=94
Для продолжения нажмите любую клавишу . . .
Dostları ilə paylaş: |