结构数组:找连环数字 为什么输出不正确!

来源:百度知道 编辑:UC知道 时间:2024/06/07 04:54:23
用了两个子函数,一个用于统计,一个打印结果。为什么统计的函数中明明规定了条件包含两数相等的情况,而输出的结果就是没有?
我的源代码如下:
#include<stdio.h>
#include<stdlib.h>

struct group {
int num1,num2,count1,count2;
};

typedef struct group Group;

void findnear(int *,int,Group *);

void printresult(Group *);

main()
{
Group times[46]={{0,0,0,0}};
int a,b,N,temp,*numarray,i;

printf("请输入元素个数:\nN=");
scanf("%d",&N);
numarray=malloc(sizeof(int)*N);
printf("请输入这%d个元素:\n",N);
for(i=0;i<=N-2;i++)
{
scanf("%d",&temp);
getchar();
if(temp>9||temp<0)
{
printf("Error input.");
system("pause");
return 0;
}
else
numarray[i]=temp;

#include<stdio.h>
#include<stdlib.h>

struct group {
int num1,num2,count1,count2;
};

typedef struct group Group;

void findnear(int *,int,Group *);

void printresult(Group *);

main()
{
Group times[46]={{0,0,0,0}};
int a,b,N,temp,*numarray,i;

printf("请输入元素个数:\nN=");
scanf("%d",&N);
numarray=malloc(sizeof(int)*N);
printf("请输入这%d个元素:\n",N);
for(i=0;i<=N-2;i++)
{
scanf("%d",&temp);
getchar();
if(temp>9||temp<0)
{
printf("Error input.");
system("pause");
return 0;
}
else
numarray[i]=temp;
}
findnear(numarray,N,times);
printresult(times);

system("pause");
return 0;
}

void findnear(int *array,int size,Group *ti