#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int main()
{
int arr[5] = { 300,350,200,400,250 };
int i = 0;
int t = 0;
for (; i < 5; i++)
{
if (arr[i] > arr[t])
{
t = i;
}
}
cout << "arr[" << t << "]" << "=" << arr[t] << endl;
system("pause");
return 0;
}
二.数组元素逆置
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int main()
{
int arr[] = { 1,2,3,4,5 };
int i = 0;
int left = 0;
int right = sizeof(arr) / sizeof(arr[0]) - 1;
int t = 0;
cout << "原数据为:" << endl;
for (; i <= right; i++)
{
cout << arr[i] << " ";
}
cout << endl;
while (left < right)
{
t = arr[left];
arr[left] = arr[right];
arr[right] = t;
left++;
right--;
}
cout << "逆置后的数据为:" << endl;
for (i = 0; i <= 4; i++)
{
cout << arr[i] << " ";
}
cout << endl;
system("pause");
return 0;
}
三.冒泡排序
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
using namespace std;
int main()
{
int arr[] = {4,2,8,0,5,7,1,3,9};
int temp = 0;
int i = 0;//排序次数
int j = 0;//排序到第几个
int length = sizeof(arr) / sizeof(arr[0]);
for (i = 0; i < length-1; i++)//循环次数:数组长度-1
{
for (j = 0; j < length - 1 - i; j++)//比较次数:数组长度-i-1
{
if (arr[j] < arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
for (i = 0; i < length; i++)
{
cout << arr[i] << " ";
}
cout << endl;
system("pause");
return 0;
}
一维数组一维数组定义方式一维数组的数组名一维数组练习案例一.#define _CRT_SECURE_NO_WARNINGS #include<iostream>using namespace std;int main(){ int arr[5] = { 300,350,200,400,250 }; int i = 0; int t = 0; for (; i < 5; i++) { if (arr[i] >