编程,输入n和n个整数,输出其中负数、0、和正数的个数。
时间: 2024-05-24 13:11:57 浏览: 94
n = int(input("请输入整数个数:"))
negatives = 0 # 负数个数
zeros = 0 # 0的个数
positives = 0 # 正数个数
for i in range(n):
num = int(input("请输入整数:"))
if num < 0:
negatives += 1
elif num == 0:
zeros += 1
else:
positives += 1
print("负数个数:", negatives)
print("0的个数:", zeros)
print("正数个数:", positives)
相关问题
编程,输入n和n个整数,输出其中负数、0、和正数的个数
n = int(input("请输入整数的个数:"))
negative = 0
zero = 0
positive = 0
for i in range(n):
num = int(input("请输入整数:"))
if num < 0:
negative += 1
elif num == 0:
zero += 1
else:
positive += 1
print("负数的个数为:", negative)
print("0的个数为:", zero)
print("正数的个数为:", positive)
编程,输入n和n个整数,输出其中负数、0、和正数的个数。 C语言
#include <stdio.h>
int main() {
int n, num, pos = 0, neg = 0, zero = 0;
scanf("%d", &n);
for(int i = 0; i < n; i++) {
scanf("%d", &num);
if(num > 0) pos++;
else if(num < 0) neg++;
else zero++;
}
printf("positive: %d\nnegative: %d\nzero: %d\n", pos, neg, zero);
return 0;
}
阅读全文