码迷,mamicode.com
首页 > 编程语言 > 详细

三个数从小到大排序

时间:2014-11-02 17:59:16      阅读:120      评论:0      收藏:0      [点我收藏+]

标签:style   blog   io   color   ar   os   for   sp   strong   

三个数从小到大排序

描述

现在要写一个程序,实现给三个数排序的功能

 
输入
输入三个正整数
输出
给输入的三个正整数排序
样例输入
20 7 33
样例输出
7 20 33

 
#include <iostream>
using namespace std;
int main()
{
    int arr[3];
    for(int i=0 ;i<3 ; i++)
        cin>>arr[i];
    int temp;
    for(int i =0 ;i<3; i++)
    {
        for(int j = 0;j<2-i;j++)
        {
            if(arr[j] >arr[j+1]){
                temp = arr[j];
                arr[j] = arr[j+1];
                arr[j+1] = temp;
            }
        }
    }
    for(int k = 0;k<3;k++)
        cout<<arr[k]<<" ";
    
    return 0;
}
            

 

三个数从小到大排序

标签:style   blog   io   color   ar   os   for   sp   strong   

原文地址:http://www.cnblogs.com/imwtr/p/4069456.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!