C++/Source

배열을 이용한 카운터 방법..

gandus 2010. 4. 13. 15:39


#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 check[10] = {0};


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

                arr[i] = rand() % 100;


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

                check [ arr[i] / 10 ]++;  // 체크를한다


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

        {

                cout<< i * 10 <<" ~ " << (i+1) *10 <<" 까지의갯수는: "<< check[i]<<endl;

        }

}