面试_每天一道_1
来源:互联网 发布:php代理商管理系统 编辑:程序博客网 时间:2024/05/16 02:07
#include "stdafx.h"
#include <iostream>
#include <math.h>
//1、有一个整数数组,请求出两两之差绝对值最小的值,
//记住,只要得出最小值即可,不需要求出是哪两个数。
int MiniAbs(int *intArray, int intLength)
{
int tempMax, tempMin, i;
for(tempMax = intArray[0], tempMin = intArray[0], i = 1; i < intLength; i ++)
{
if(intArray[i] > tempMax) tempMax = intArray[i];
if(intArray[i] < tempMin) tempMin = intArray[i];
}
std::cout<<tempMax<<", "<<tempMin<<std::endl;
return abs(tempMax - tempMin);
}
int _tmain(int argc, _TCHAR* argv[])
{
int testArray[10] = {2, 54, 34, 5, -4, 67, 543, -45, 123, -5};
int result = MiniAbs(testArray, 10);
std::cout<<"最小值为:"<<result<<std::endl;
return 0;
}
#include <iostream>
#include <math.h>
//1、有一个整数数组,请求出两两之差绝对值最小的值,
//记住,只要得出最小值即可,不需要求出是哪两个数。
int MiniAbs(int *intArray, int intLength)
{
int tempMax, tempMin, i;
for(tempMax = intArray[0], tempMin = intArray[0], i = 1; i < intLength; i ++)
{
if(intArray[i] > tempMax) tempMax = intArray[i];
if(intArray[i] < tempMin) tempMin = intArray[i];
}
std::cout<<tempMax<<", "<<tempMin<<std::endl;
return abs(tempMax - tempMin);
}
int _tmain(int argc, _TCHAR* argv[])
{
int testArray[10] = {2, 54, 34, 5, -4, 67, 543, -45, 123, -5};
int result = MiniAbs(testArray, 10);
std::cout<<"最小值为:"<<result<<std::endl;
return 0;
}
- 面试_每天一道_1
- 每天一道leetcode题目_(1)
- 每天来点算法_1
- 线性代数_廖艾贤_1
- 日常_疑难杂症_1
- 面试信息获取_1
- 嵌入式面试试题_1
- 面试:数组:Topk _1
- C++面试笔记_1
- 每天一道算法_4_Hangover
- 每天一道算法_7_Biorhythms
- 每天一道ACM(一)
- 每天一道智力题
- 【每天一道Linux命令】
- 【每天一道Linux命令】
- 【每天一道算法题】
- 【每天一道Linux题】
- 【每天一道算法题】
- leetcode_question_121 Best Time to Buy and Sell Stock
- log file switch and log file sync
- oracle的nvl和sql server的isnull
- p不能嵌入<div>
- Extjs里表格grid显示日期类型数据
- 面试_每天一道_1
- 效率类的app度过艰难期-美国专业APP营销公司的21种
- Java IO 总结
- (总结)CentOS Linux搭建SVN Server配置详解
- Java note
- 一步步教你如何源码编译Recovery
- extjs4 grid 日期出现0NaN-NaN-NaN
- 排序算法之冒泡排序
- 2014年阿里巴巴9月14号笔试题