hyqd.net
当前位置:首页 >> FrEE pAsCAl编程输入3个整数,从小到大排序后输出 >>

FrEE pAsCAl编程输入3个整数,从小到大排序后输出

这道题用选择排序来做,核心部分: for i:=1 to n-1 do for j:=i+1 to n do if a[i]>a[j] then begin t:=a[j]; a[j]:=a[i]; a[i]:=t; end;参考程序(pascal):const n=3;var a:array[1..3] of longint; i,j,t:longint;begin for i:=1 to n do read(a[i]); readln; for i:=1 to n-1 do

var a,b,c,h:integer; begin readln(a,b,c); if a>b then begin h:=a;a:=b;b:=h; end; if b>c then begin h:=b;b:=c;c:=h; end;//在进行完以上两次判断及交换后,最大的数会被放到c当中 if a>b then begin//比较a,b的大小并把小的放到a中即完成排序 h:=a;a:=b;b:=h; end; writeln(a,' ',b,' ',c); end.

var a,b,c;begin readln(a,b,c); if a>b and b>=c then writeln(a,b,c); if a>c and c>=b then writeln(a,c,b); if b>a and a>=c then writeln(b,a,c); if b>c and c>=a then writeln(b,c,a); if c>a and a>=b then writeln(c,a,b); if c>b and b>=a then writeln(c,b,a); if a=b and b=c then writeln(a,b,c);end.

var a,b,c,t:integer;begin readln(a,b,c); if a 评论0 0 0

var max,min,a,b,c:longint;beginreadln(a,b,c);max:=a;min:=a;if b>max then max:=b;if c>max then max:=c;if b 评论0 0 0

我的程序不仅能对三个数进行排序,而且能对500000个数进行排序.首先输入一个数N,表示有N个数(你的要求的话就是输入3)然后输入N个数后加回车就是了.基本思路就是快速排序.program sort_Hewr;const maxn=500000;var a:array[0..

program p35;var a,b,c,x,y,z:integer;beginreadln(x);a:=x mod 10;b:=(x mod 100) div 10;c:=x div 100;for z:=1 to 6 dobeginif b>a thenbeginy:=b;b:=a;a:=y;end;if c>a thenbeginy:=c;c:=a;a:=y;end;if c>b thenbeginy:=c;c:=b;b:=y;end;end;writeln(a,b,c);readln;end.

var a,b,c:longint;procedure swap(var x,y:longint);var t:longint;begint:=x; x:=y; y:=t;end;procedure sort;beginif a>b then swap(a,b);if a>c then swap(a,c);if b>c then swap(b,c);end;beginreadln(a,b,c);sort;writeln(a,' ',b.' ',c);end.

s=1+3+5.. for i=0 to 49 do s:=s+2*i+1

var a:array[1..10]of longint; i,j,t:longint;begin for i:=1 to 10 do readln(a[i]); for i:=1 to 9 do for j:=i+1 to 10 do if a[i]>a[i] then begin t:=a[i]; a[i]:=a[j]; a[j]:=t; end; for i:=1 to 10 do write(a[i],' '); writeln;end.第一遍每次for都找出第i小的整数,保存在a[i]数组里,最后按顺序输出.

相关文档
网站首页 | 网站地图
All rights reserved Powered by www.hyqd.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com