ex76122.cpp

来源:互联网 发布:淘宝企业店运营方案 编辑:程序博客网 时间:2024/05/21 22:50
 /**************************************************************************
PURPOSE:    calculate the counts of positive and negative numbers in an array
TIME: 08/10/25
AUTHOR:    ch8_daniel
INPUT:    arr------an array contains numbers
OUTPUT:    the counts of positive and negative numbers
VERSION:    1.0
**************************************************************************/

#include <iostream>

using namespace std;

int main()
{
    const int length = 12;    // the length of the array;
    int arr[length] = {1,2,4,5,-5,-2,4,-5,7,12,-3,-22};
    int pos = 0;
    int neg = 0;
    for(int i = 0;i < 12;i++){
        if(arr[i] < 0) neg++;
        if(arr[i] > 0) pos++;
    }
    cout << ">>The count of positive numbers in the array is : " << pos << endl
    << ">>The count of negative numbers in the array is: " << neg;    
  return 0;
}
原创粉丝点击