C++/Source

난수 배열을 홀 짝 정렬.

gandus 2010. 4. 13. 15:45

 


#include<cmath>

#include<ctime>

using namespace std;



void main ()

{

        srand((unsigned)time(NULL));


        const int SIZE = 100;

        int i=0;

        int arr[SIZE] = {0};

        int cnt=0;


        for (i=0; i < SIZE; i++)     // 난수를입력한다

                arr[i] = rand() % 100;


        for(i=0; i< SIZE; i++)

                if (arr[i] % 2 == 0)

                        cnt++;


        cout<< "짝수의갯수는"<<cnt <<endl;

        cout<< "홀수의갯수는"<<SIZE - cnt <<endl;