...a数组中的元素包含了正整数,负整数和零,分别统计正整数,负..._百...
发布网友
发布时间:2024-10-13 12:41
我来回答
共2个回答
热心网友
时间:2024-11-16 22:57
这段代码我已经给你编译通过了,有不明白的可以再问我。
#include <stdio.h>
int statistics(int *pdata, int *ppositiveNum,
int *pnegaiveNum, int *zeroNum, int dataLen);
int main(void)
{
int posNum = 0; /*正数的个数*/
int negaNum = 0; /*负数的个数*/
int zerNum =0; /*零的个数*/
int a[20] = {0, 3, 4, 4, 2, 20, -32, -43, -9, 423, -32,
0, 43, 24, 43, -4, 22, 432, 343, 2};
int result = 0;
result = statistics(a, &posNum, &negaNum, &zerNum, strlen(a));
printf("> 0 is %d, <0 is %d, =0 is %d \n",posNum, negaNum, zerNum);
}
int statistics(int *pdata, int *ppositiveNum,
int *pnegaiveNum, int *zeroNum, int dataLen)
{
int *pp = NULL;
int i =0;
if((ppositiveNum == NULL) || (pnegaiveNum == NULL) ||
(zeroNum == NULL) || (pdata == NULL) || (dataLen == 0))
{
return -1;
}
else
{
pp = pdata;
for(i = 0; i < dataLen; i++)
{
if(*(pp + i) > 0)
{
*ppositiveNum += 1;
}
else if(*(pp + i) <0)
{
*pnegaiveNum += 1;
}
else
{
*zeroNum +=1;
}
}
}
return 0;
}
热心网友
时间:2024-11-16 23:01
42.