C 语言编程:输入10个整数,将其中最小的数与第一个数对换

来源:互联网 发布:做淘宝客的步骤有哪些 编辑:程序博客网 时间:2024/05/15 23:46


题目链接:http://zhidao.baidu.com/question/1575425940375460260.html


做而论道编程如下:


#include<iostream>

using namespace std;


void min(int *a, int m)

{

    int j, temp, n;

    

    temp = a[0];

    n = 0;


    for(j = 1; j < m; j++) 

      if (a[j] < temp)  {temp = a[j];  n = j;}//找最小值及其位置


    if(n) {a[n] = a[0]; a[0] = temp;}     //放在a0

}


int main()

{

    int a[10], i;


    for(i = 0; i < 10; i++)  cin >> a[i];


    for(i = 0; i < 10; i++)  cout << a[i] << ' ';  cout << endl; 


    min(a, 10);


    for(i = 0; i < 10; i++)  cout << a[i] << ' ';  cout << endl; 


    return 0;

}


0 0
原创粉丝点击