C语言 编写程序,求二维数组中的最小元素及其下标

用C语言编程

第1个回答  推荐于2016-02-15
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

void get_array(int * buf, int num)
{
int i = 0;
srand((unsigned int)time(NULL));

for (; i < num; i++)
{
buf[i] = rand() % 100 + 1;
}
}

void show_array(int * buf, int num)
{
int i = 0;
for (; i < num; i ++)
{
printf("buf[%d] = %d\n", i, buf[i]);
}
}

void get_min(int *buf, int num, int * result, int * pos)
{
int icount = 0;
*result = buf[0];

for (; icount < num; icount ++)
{
if (*result < buf[icount])
{
*result = buf[icount];
*pos = icount;
}
}
}

int main()
{
int buf[10] = {0};
int res = 0, pos = 0;

get_array(buf, 10);
show_array(buf, 10);

get_min(buf, 10, &res, &pos);

printf("\nresult = %d, pos = %d\n", res, pos);

getchar();
return 0;
}本回答被提问者和网友采纳