// 求出数组中相邻三个数之和最大的一组 #include "stdafx.h" #include <stdio.h> #include <math.h> #include <iostream> #include <String> using namespace std; int main() { // 输入数组的最大值 int array_size = 100; cout<<"please input the array_size of the array : "; cin>>array_size; int num[10000]; for(int i = 0; i < array_size; i++) { num[i] = rand() % (array_size + 1); cout<< i <<" the random number is :"<<num[i]<<endl; } // 保存最大的值 int max_num = 0; int max_index = 0; for(int i=0; i<array_size - 2; i++) { int temp_max = 0; for(int j=i; j<i+3; j++) { temp_max += num[j]; } if(temp_max > max_num) { max_num = temp_max; max_index = i; } } cout<<"the max num of the three in the array is :"<<max_num<<endl; cout<<"the max num index of the array is : "<<max_index<<endl; system("pause"); }