C语言编程>第七周 ⑤ 请编写一个函数void fun(int*s,int t,int*result),用来求出数组的最小元素在数组中的下标,并存放在result所指的存储单元中。

例题:请编写一个函数void fun(ints,int t,intresult),用来求出数组的最小元素在数组中的下标,并存放在result所指的存储单元中。

例如,输入如下整数: 564,165,567,121,948,324,329,454,5345,783,434,124,561,985,555 则输出结果为:3,121。
请勿改动主函数main与其它函数中的任何内容,仅在函数fun的花括号中填入所编写的若干语句。

代码如下:

#include
#include
void fun(int*s,int t,int*result)
{
     
	int temp,min;
	min=s[0];
	for(temp=0;temp<t;temp++)
	if(s[temp]<min)
	{
     
		min=s[temp];
		*result=temp;
	}
}
main()
{
     
	int store[15]={
     564,165,567,121,948,324,329,454,5345,783,434,124,561,985,555},result;
	FILE*out;
	fun(store,10,&result);
	printf("%d,%d\n",result,store[result]);
	out=fopen("outfile.dat","w");
	fprintf(out,"%d\n%d",result,store[result]);
	fclose(out);
}

输出运行窗口如下:
C语言编程>第七周 ⑤ 请编写一个函数void fun(int*s,int t,int*result),用来求出数组的最小元素在数组中的下标,并存放在result所指的存储单元中。_第1张图片

越努力越幸运!
加油,奥力给!!!

你可能感兴趣的:(C语言程序设计,c语言,c++,程序设计,编程语言,计算机二级C语言上机题)