三九宝宝网宝宝教育教学论文

c语言用冒泡法对十个整数按升序排序

03月12日 编辑 39baobao.com

[C语言编程题题目描述使用冒泡排序法对数组元素从小到大进行排序]#include "stdafx.h" #include <iostream> #include <stdlib.h> using namespace std; void sort(int arry[],int counts)//冒泡排序法 { for(int i=0;i<counts;i++) { for(in...+阅读

%d"a[10]; j++)

if(a[k]<,k;i++)

printf("

#include

scanf("

}

}

for(i=0;;%2d"

for(i=0;;10;

int i,&,max;stdio;j

for(i=0;the i

{

k=i;10,a[i]);main(void)

{

int 0;

return :",j;number;10;a[i]).h>10;a[j])

{

max=a[j];

printf("

a[i]=max;i<

int

for(j=i;

a[j]=a[i];);i<

如何使用汇编语言实现冒泡排序

内存以BUF单元开始有若干单字节有符号数,编程实现从大到小排序并以十进制输出。 code segment assume cs:code org 100h start:jmp begin buf db 3,4,5,0,-1,-2,-3 n dw $-buf begin:push cs pop ds push cs pop es lea si,buf mov cx,n call sort mov cx,n lea si,buf 1: lodsb cbw call dispaxs loop 1 mov ah,4ch int 21h ;============================================= ; 字节数组排序(冒泡排序) sort proc near ; 数组元素个数置入cx,首地址置入 si push ax push cx push dx push si push di pushf push cx pop dx dec dx sortl1: mov cx,dx mov di,si sortl2: mov al,[di+1] cmp al,[di] jl sortnext ; 无符号数排序改为 jb xchg al,[di] mov [di+1],al sortnext: inc di loop sortl2 dec dx jnz sortl1 popf pop di pop si pop dx pop cx pop ax ret sort endp ;==================================================== ; 将要显示的有符号数置于 ax 中 DISPAXS PROC NEAR PUSH AX PUSH BX PUSH CX PUSH DX PUSH SI PUSH DI PUSH BP PUSH DS PUSH ES PUSHF PUSH CS POP DS PUSH CS POP ES MOV CX,6 LEA DI,DISPAXSS DISPAXS: MOV BYTE PTR [DI],32 INC DI LOOP DISPAXS PUSH AX MOV DL,32 MOV AH,2 INT 21H POP AX MOV BYTE PTR NZS,0 MOV BYTE PTR SIGNS,0 CMP AX,0 JGE DISPAXS0 MOV BYTE PTR SIGNS,1 NEG AX DISPAXS0: PUSH AX LEA SI,DIVARRS LEA DI,DISPAXSS INC DI MOV CX,5 DISPAXS1: POP AX MOV DX,0 MOV BX,[SI] DIV BX PUSH DX CMP AL,0 JNE DISPAXS2 CMP BYTE PTR NZS,1 JE DISPAXS2 CMP CX,1 JE DISPAXS2 MOV DL,20H JMP DISPAXS3 DISPAXS2: ADD AL,30H MOV DL,AL MOV BYTE PTR NZS,1 DISPAXS3: MOV BYTE PTR[DI],DL INC SI INC SI INC DI LOOP DISPAXS1 POP DX CMP BYTE PTR SIGNS,1 JNE DISPAXS6 LEA SI,DISPAXSS ADD SI,5 DISPAXS4: CMP BYTE PTR [SI],32 JE DISPAXS5 DEC SI JMP DISPAXS4 DISPAXS5: MOV BYTE PTR [SI],'-' DISPAXS6: LEA DX,DISPAXSS MOV AH,9 INT 21H POPF POP ES POP DS POP BP POP DI POP SI POP DX POP CX POP BX POP AX RET DIVARRS DW 10000,1000,100,10,1 NZS DB 0 SIGNS DB 0 DISPAXSS DB 32,32,32,32,32,32,'$' DISPAXS ENDP ;================================================ code ends end start

c语言用指针进行冒泡排序

void main(void)

{

int a[10]={2,4,6,7,8,1,3,5,9,10};

int *p1=a,*p2=a+9,temp;

printf("排序前: \n");

for(p1=a;p1{

printf("%d ",*p1);

}

for(p1=a;p1for(p2=p1+1;p2{if(*p2>*p1)/*这也要加个判断语句*/

{

temp=*p1;

*p1=*p2;

*p2=temp;

}

}

printf("\n");

printf("排序后: \n");

for(p1=a;p1{

printf("%d ",*p1);

}

printf("\n");

getch();/*加一中断*/

}

以下为关联文档:

C语言题用二维数组和冒泡排序#include<stdio.h> #define n 4 int main() { char a[n][30]; char tempstr[30]; char ch[30]; int b[n]; int i,j,temp; printf("你好使用者,我是一个自动分析程序,请输入你想...

C语言冒泡排序#include<stdio.h> #define MAX 10 // #include <stdio.h> #define N 10 int main (){ int i,j,t,a[N]; printf("please input ten numbers:\n"); for (i=0;i<N;i++) scanf("%d...

C语言由键盘输入十个整数按从大到小和从小到大分别输出排序结这是你需要的东西!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #include<stdio.h> void main() { int a[10]={0},i,j,temp; printf("请输入10个数字\n"); for (i=0;i<10;i++) { scanf("%d",&a[i]); } for (i=0;...

C语言:由键盘输入十个整数按从大到小和从小到大分别输出排序结这是你需要的东西!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! #include<stdio.h> void main() { int a[10]={0},i,j,temp; printf("请输入10个数字\n"); for (i=0;i<10;i++) { scanf("%d",&a[i]); } for (i=0;...

用C语言的函数做冒泡法排序#include #define M 10 void Bubble(int a[]) { int t; for(int i=0;ifor(int j=i+1;jif(a[j]>a[i]) { t=a[j]; a[j]=a[i]; a[i]=t; } for(i=0;icout} void main() { int a[...

C语言冒泡排序算法要用函数从小到大排序 void paixu(double a[],int N) { double temp; int i,j; for(i=0;i<N;i++) { for(j=i+1;j<N-i;j++) { if(a[i]>a[j]) {temp=a[i];a[i]=a[j];a[j]=temp;} } } }...

选择排序冒泡排序 C语言从程序运行需要的时间和储存空间来看,这两个吧,选择排序用的时间较少。我给你举个例子,这是一个比较直观的例子: 有十个数:10,9,8,7,6,5,4,3,2,1 。将他们按从小到大的顺序排成一...

输入10个整数用C语言随机输入10个整数用冒泡排序法对这些整数printf("plese input the number\n"); for(i=0;i<10;i++) scanf("%d",&a[i]); for(i=0;i<10;i++) /*冒泡排序*/ for(j=1;j<n-i ;j++) if(a[j-1]>a[j] ) { temp=a[j-1]; a[j-1]=a...

编写程序用函数实现对10个整数的冒泡排序c语言#include <stdio.h> void main() { int a[10]; int i,j,t,flag; printf("input 10 numbers :\n"); for (i=0;i<10;i++) scanf("%d",&a[i]); printf("\n"); for(j=0;j<9;j++) for(i...

推荐阅读
图文推荐