输入 66 个数字,它们要么是正数,要么是负数。
请你统计并输出正数的个数。
输入格式
六个数字,每个占一行。
输出格式
输出格式为 x positive numbers
,其中 xx 为正数的个数。
数据范围
输入数字的绝对值不超过 100100。
输入样例:
1. 7 2. -5 3. 6 4. -3.4 5. 4.6 6. 12
输出样例:
4 positive numbers
代码
1. #include <iostream> 2. using namespace std; 3. 4. int main() 5. { 6. double a[6]; 7. int cnt = 0; 8. int n = sizeof(a) / sizeof(a[0]); 9. for (int i = 0; i < n; i++) { 10. cin >> a[i]; 11. if (a[i] > 0) { 12. cnt++; 13. } 14. } 15. cout << cnt << " positive numbers" << endl; 16. return 0; 17. }
收获点:
- c++获取数组长度 a = sizeof(a) / sizeof(a[0]);
- 可以定义一个数组,然后在循环里通过 cin >> a[i]获取