jixiaowu

60.编程统计数组a中正数、0、负数的个数

#include<iostream>
using namespace std;

int main()
{
    int x=0,y=0,z=0;
    int a[10];

    cout<<"please input 10 numbers:"<<endl;
    for(int i=0;i<10;i++)
    {
        cin>>a[i];
    }

    for(int j=0;j<10;j++)
    {
        if(a[j]==0)
        {
            x++;
        }
    }

    for(int m=0;m<10;m++)
    {
        if(a[m]>0)
        {
            y++;
        }
    }

    for(int n=0;n<10;n++)
    {
        if(a[n]<0)
        {
            z++;
        }
    }
    cout<<"数组中有"<<x<<"个零"<<endl;
    cout<<"数组中有"<<y<<"个整数"<<endl;
    cout<<"数组中有"<<z<<"个负数"<<endl;

    return 0;
}

 

分类:

技术点:

相关文章: