题解 | #统计数据正负个数#
统计数据正负个数
http://www.nowcoder.com/practice/3f33889582934a09b4e3ddd3cc976226
#include<stdio.h>
int main() {
int a[10];
int positive = 0, negative = 0; //初始化正负数值
for (int i = 0; i < 10; i++) { //循环输入10个数
scanf("%d ", &a[i]);
if (a[i] > 0)
positive++; //判断输入整数是否大于0,是则整数自加1
else negative++; //否则负数自加1
}
printf("positive:%d\nnegative:%d", positive, negative);
return 0;
}
int main() {
int a[10];
int positive = 0, negative = 0; //初始化正负数值
for (int i = 0; i < 10; i++) { //循环输入10个数
scanf("%d ", &a[i]);
if (a[i] > 0)
positive++; //判断输入整数是否大于0,是则整数自加1
else negative++; //否则负数自加1
}
printf("positive:%d\nnegative:%d", positive, negative);
return 0;
}