编程:从键盘输入10个整数,统计其中正数、负数和零的个数,并在屏幕上依次输出。
时间: 2024-05-04 15:15:14 浏览: 15
好的,这个问题是关于编程的,我可以帮您回答。下面是一个示例代码:
```python
pos_count = 0
neg_count = 0
zero_count = 0
for i in range(10):
num = int(input("请输入第%d个整数:" % (i+1)))
if num > 0:
pos_count += 1
elif num < 0:
neg_count += 1
else:
zero_count += 1
print("正数的个数为:%d" % pos_count)
print("负数的个数为:%d" % neg_count)
print("零的个数为:%d" % zero_count)
```
您可以运行这个代码,从键盘输入10个整数,程序将会统计其中正数、负数和零的个数,并依次输出在屏幕上。
相关问题
从键盘输入十个整数统计其中正数,负数和0的个数,并在屏幕上依次输出
以下是 Python 代码实现:
```python
positive_count = 0 # 正数个数
negative_count = 0 # 负数个数
zero_count = 0 # 0 的个数
for i in range(10):
num = int(input("请输入第 %d 个整数:" % (i+1)))
if num > 0:
positive_count += 1
elif num < 0:
negative_count += 1
else:
zero_count += 1
print("正数个数:%d" % positive_count)
print("负数个数:%d" % negative_count)
print("0 的个数:%d" % zero_count)
```
运行代码后,会提示用户依次输入 10 个整数,然后统计其中正数、负数和 0 的个数,并在屏幕上输出结果。
用c语言从键盘输入十个整数统计其中正数,负数和0的个数,并在屏幕上依次输出
下面是用 C 语言实现从键盘输入十个整数统计其中正数,负数和0的个数,并在屏幕上依次输出的代码:
```c
#include <stdio.h>
int main() {
int num, positive_count = 0, negative_count = 0, zero_count = 0;
// 读入十个整数
for (int i = 0; i < 10; i++) {
printf("请输入第 %d 个整数:", i+1);
scanf("%d", &num);
// 统计正数、负数和0的个数
if (num > 0) {
positive_count++;
} else if (num < 0) {
negative_count++;
} else {
zero_count++;
}
}
// 输出结果
printf("正数个数:%d\n", positive_count);
printf("负数个数:%d\n", negative_count);
printf("0的个数:%d\n", zero_count);
return 0;
}
```
使用 for 循环读入十个整数,并依次统计正数、负数和0的个数。最后输出结果。
相关推荐
![c](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)