1 条题解

  • 0
    @ 2025-4-7 21:29:27

    C :

    #include<stdio.h>
    #include<string.h>
    int main(){
    	int a[3],i,j,temp;
    	for(i=0;i<3;++i){
    		scanf("%d",&a[i]);
    	}
    	for(i=0;i<2;i++){
    		for(j=0;j<2-i;++j){
    			if(a[j]>a[j+1]){
    				temp = a[j];
    				a[j] = a[j+1];
    				a[j+1] = temp;
    			}
    		}
    	}
    	for(i=0;i<3;++i){
    		printf("%d ",a[i]);
    	}
    	return 0;
    } 
    

    C++ :

    #include<iostream>
    using namespace std;
    void swap(int *p,int *q)
    {
    	int t=*p;
    	*p=*q;
    	*q=t;
    }
    int main()
    {
    	int a,b,c;
    	cin>>a>>b>>c;
    	int *p1=&a,*p2=&b,*p3=&c;
    	if (a>b) swap(p1,p2);
    	if (a>c) swap(p1,p3);
    	if (b>c) swap(p2,p3);
    	cout<<*p1<<" "<<*p2<<" "<<*p3<<" "<<endl;
    	return 0;
    }
    

    Pascal :

    var
        y,z,i,x,j:integer;
        a:array [1..3] of integer;
    begin
      readln(a[1],a[2],a[3]);
      for i:=1 to 3 do
       for j:=1 to 3 do
       if a[i]>a[j] then begin x:=a[i]; a[i]:=a[j]; a[j]:=x; end;
       for i:=3 downto 1 do write(a[i],' ');
        
    end.
    
    • 1

    C语言程序设计教程(第三版)课后习题10.1

    信息

    ID
    1575
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    (无)
    递交数
    0
    已通过
    0
    上传者