题解 | #统计数据正负个数#
统计数据正负个数
https://www.nowcoder.com/practice/3f33889582934a09b4e3ddd3cc976226
#include <stdio.h> int main() { // 由题知需要定义int类型的数组(范围-2^31 ~ 2^31 - 1) int scores[10] = {0}; unsigned short positive_num = 0, negative_num = 0; for (int i = 0; i < 10; i++) { scanf("%d", &scores[i]); if (scores[i] > 0) positive_num++;//统计正数的个数 else if (scores[i] < 0) negative_num++;//统计负数的个数 else continue; } printf("positive:%hu\nnegative:%hu\n", positive_num, negative_num); return 0; }