c++实现功能:求整型数组中的最小值及其下标,并输出
发布网友
发布时间:2022-05-10 19:26
我来回答
共1个回答
热心网友
时间:2023-10-24 16:03
#include "iostream"
using namespace std;
int main()
{
int a[10] = { 1, 2, 3, 0, 6, 7, 0, 9, 0, 8 };
int b = a[0];
int c[10], d = 0;
for (int i = 1; i < 10; i++)
{
if (b > a[i])
{
b = a[i];
d = 0;
c[d] = i;
}
else if (b == a[i])
{
d++;
c[d] = i;
}
}
cout << "最小值为:" << b << endl;
cout << "下标为:" << endl;
for ( int i = 0; i <= d; i++)
{
cout << c[i] << " ";
}
system("pause");
return 0;
}