帮忙写一个小测试程序

来源:百度知道 编辑:UC知道 时间:2024/06/03 19:57:16
帮忙写一个小程序测试一下下面这个找出数组中最大数字位置的程序
int findMax(int *a, int len)
{
int i,position;
if (len==0)
{
return 0
}
else
{
position = 0;
}

for(i=1;i<len;i++)
{
if(a[position]<a[i])
{
position = i;
}
}
return position
}
测试程序:int main (int argc, char *argv[])

// test.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "stdlib.h"
#include "string.h"

int findMax(int *a, int len)
{
int i,position;
if (len==0)
{
return 0;
}
else
{
position = 0;
}

for(i=1;i<len;i++)
{
if(a[position]<a[i])
{
position = i;
}
}
return position;
}

int main(int argc, char* argv[])
{
int *b;
if (argc==0){
printf("输入数组");
return 0;
}
b=(int *)malloc(sizeof(int)*argc);
for (int i=1;i<argc;i++){
*(b+i)=0;
int n=1;
for (int j=strlen(argv[i])-1;j>=0;j--){
*(b+i)+=n*(int)(*(argv[i]+j)-'0');
n*=10;
}
printf("%d\n",*(b+i));
}
printf("%d\n",findMax(b,argc));
free((void *)b);