首页 > 其他 > 详细

问题 1065: 2004年秋浙江省计算机等级考试二级C 编程题(1)

时间:2017-06-28 11:33:44      阅读:457      评论:0      收藏:0      [点我收藏+]
/********************************************************************
@file     Main.cpp
@date     2017-6-28 10:45:08
@author   Zoro_Tiger
@brief    问题 1065: 2004年秋浙江省计算机等级考试二级C 编程题(1)
          http://www.dotcpp.com/oj/problem1065.html
********************************************************************/
//!头文件
#include <cstdio>
#include <cmath>

//!宏定义
#define ARRAY_SIZE 10

//!程序入口
int main(int argc, const char* argv[])
{
    //!变量声明
    int array[ARRAY_SIZE]= { 0 };

    //!读取输入并找到最小值
    int index = 0;
    for (int i = 0; i < ARRAY_SIZE; ++i)
    {
        //!读取输入
        scanf("%d", array + i);

        //!找到最小值
        if (i != 0 && std::abs(array[i]) < std::abs(array[index])) //!绝对值最小,看错题了
        {
            index = i;
        }
    }

    //!交换数值
    if (index != ARRAY_SIZE - 1) //!避免自身交换
    {
        array[index] += array[ARRAY_SIZE - 1];
        array[ARRAY_SIZE - 1] = array[index] - array[ARRAY_SIZE - 1];
        array[index] = array[index] - array[ARRAY_SIZE - 1];
    }

    //!输出结果
    for (int i = 0; i < ARRAY_SIZE; ++i)
    {
        if (0 == i)
        {
            printf("%d", array[i]);
        }
        else
        {
            printf(" %d", array[i]);
        }
    }
    
    //!返回系统
    return 0;
}

 

问题 1065: 2004年秋浙江省计算机等级考试二级C 编程题(1)

原文:http://www.cnblogs.com/roronoa-zoro-zrh/p/7088764.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!