用数组编写将5个整数(整数任给)按从小到大的次序排列的程序(C++)

用数组编写将5个整数(整数任给)按从小到大的次序排列的程序(C++),第1张

#include <iostream>

using namespace std;

int main()

{

    int i,j,t,a[5]={5,1,9,4,2};

    for(i=0;i<4;i++)

    {

        for(j=i+1;j<5;j++)

        {

           if(a[i]>a[j])

           {

               t=a[i];

               a[i]=a[j];

               a[j]=t;

           }

        }

    }

    for(i=0;i<5;i++)

      cout<<a[i]<<"  ";

      return 0;

}

冒泡排序法,顺手写的。你自己编译一下就行了

unit Unit2;

interface

uses

Classes,ADODB,SysUtils,DB,ActiveX ;

type

AllNumber = class(TThread)

private

{ Private declarations }

protected

procedure Execute; override;

procedure ADOADDEdit(ado:TADOQuery;str:String);

end;

implementation

{ Important: Methods and properties of objects in visual components can only be

used in a method called using Synchronize, for example,

Synchronize(UpdateCaption);

and UpdateCaption could look like,

procedure AllNumberUpdateCaption;

begin

Form1Caption := 'Updated in a thread';

end; }

{ AllNumber }

procedure AllNumberADOADDEdit(ado: TADOQuery; str: String);

begin

adoClose ;

adoSQLClear ;

adoSQLAdd(str) ;

adoExecSQL ;

end;

procedure AllNumberExecute;

var

ado:TADOQuery;

a,b,c,d,e,f,g,sum:Integer;

str:string;

begin

CoInitialize(nil);

ado := TADOQueryCreate(nil);

adoConnectionString := 'Provider=MicrosoftJetOLEDB40;Data Source=DataBase\datamdb;Persist Security Info=False';

FreeOnTerminate := true;

for a := 1 to 30 do

for b:= a+1 to 31 do

for c := b+1 to 32 do

for d := c+1 to 33 do

for e := d+1 to 34 do

for f := e+1 to 35 do

for g := f+1 to 36 do

begin

if (a <> b) and (a <>c) and (a<> d) and (a<>e) and (a<>f) and (a<>g) and (b<>c) and (b<>d) and (b<>e) and (b<>f) and (b<>g) and (c<>d) and (c<>e) and (c<>f) and (c<>g) and (d<>e) and (d<>f) and (d<>g) and (e<>f) and (e<>g) and (f<>g) then

begin

sum := a+b+c+d+e+f+g;

str := 'insert into numnumshu (one,two,three,four,five,six,seven,NumSum) Values('''+IntToStr(a)+''','''+IntToStr(b)+''','''+IntToStr(c)+''','''+IntToStr(d)+''','''+IntToStr(e)+''','''+IntToStr(f)+''','''+IntToStr(g)+''','''+IntToStr(sum)+''')';

ADOADDEdit(ado,str);

end;

end;

FreeAndNil(ado);

CoUninitialize();

end;

end

这个是我自己写的一个线程,用来产生所有不同的号码,不过我算得是36选七,你把它改成33选六就可以了

手机下面不是有三个键么,左边是返回键,中间那个是主页键,右边那个是功能键。

你进入菜单界面。按功能键,会出现自动排列,按时间,按最常用,等等。

安卓手机应用程序桌面快捷方式图标是可以手动移动的。

如果您卸载某一个应用程序之后出现空缺,这时您可以长按别的应用程序快捷方式手动拖动补充此空缺。

如果想添加别的应用程序快捷方式,可在应用程序中找到您想要添加的软件长按添加到桌面快捷方式。

1、点下左边虚拟按键。

2、按下编辑就可以对桌面上的图标进行整理了。

3、按住要移动的图标大概1秒左右,就可以任意拖动了。

程序如下:

#include <stdioh>

int main ()

{

int a[10];

int i, j, t;

printf ("请输入十个数:\n");

for (i = 0; i < 10; i++)

{

printf ("a[%d]=", i+1);

scanf ("%d",&a[i]);

}

for (j = 0;j < 9; j++)

for (i = 0; i < 9 - j; i++)

if (a[i] > a[i+1])

{

t = a[i];

a[i] = a[i+1];

a[i+1] = t;

}

printf ("由小到大的顺序为:\n");

for (i = 0; i < 10; i++)

{

printf ("%d,",a[i]);

}

printf ("\n");

return 0;

}

运行结果

请输入十个数:

a[1]=7

a[2]=8

a[3]=9

a[4]=6

a[5]=5

a[6]=4

a[7]=1

a[8]=2

a[9]=3

a[10]=99

由小到大的顺序为:

1,2,3,4,5,6,7,8,9,99。

冒泡排序算法的原理如下:

1、比较相邻的元素。如果第一个比第二个大,就交换他们两个。

2、对每一对相邻元素做同样的工作,从开始第一对到结尾的最后一对。在这一点,最后的元素应该会是最大的数。

3、针对所有的元素重复以上的步骤,除了最后一个。

4、持续每次对越来越少的元素重复上面的步骤,直到没有任何一对数字需要比较。

扩展资料:

冒泡排序的思想:

首先,从表头开始往后扫描数组,在扫描过程中逐对比较相领两个元素的大小。若相邻两个元素中,前面的元素大于后面的元素,则将它们互换, 称之为清去了一个逆序。

在扫描过程中,不断地将两相邻元素中的大者往后移动,最后就将数组中的最大者换到了表的最后,这正是数组中最大元素应有的位置。

然后,在剩下的数组元素中(n-1个元素)重复上面的过程,将次小元素放到倒数第2个位置。不断重复上述过程,直到剩下的数组元素为0为止,此时的数组就变为了有序。

假设数组元素的个数为西,在最坏情况下需要的比较总次数为: (n-1)+(n- 2)+2+1)- n(n-1)/2。

参考资料来源:百度百科-冒泡排序

以上就是关于用数组编写将5个整数(整数任给)按从小到大的次序排列的程序(C++)全部的内容,包括:用数组编写将5个整数(整数任给)按从小到大的次序排列的程序(C++)、排列组合算法程序、三星手机安卓应用程序的图标如何实现自动排列等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zz/9383605.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-27
下一篇 2023-04-27

发表评论

登录后才能评论

评论列表(0条)

保存