2019년 6월 24일 월요일

C++ 배열을 이용하여 주사위 던져 숫자 몇 번 나오는지 횟수 세기

이번에는
배열을 이용하여 주사위를 던졌을 경우
각 숫자가 몇 번 나오는지 알아보는 것을 해보겠습니다.
 

랜덤함수가 필요하기 때문에
ctime 헤더 파일을 넣어줍니다.
FACES라는 기호상수에 6을 넣어줍니다.( 주사위의 면을 나타냅니다.)

side[0]~side[5]로 해도 되지많은
주사위는 1~6까지의 숫자가 있으니
헷갈릴까봐 +1을 추가해서
side[0] ~side[6]까지로 해서
헷갈리지 않게 합니다.

side[(rand() % FACES)+1]
랜덤함수의 값에다가 6의 나머지 + 1 을 해주면
주사위를 던져서 값이 나온 거랑 같습니다.

그래서 그 배열 값을 ++을 해주어
회수를 증가시켜줍니다.

그리고 나서 그 값을
출력해주면 됩니다.
 

다음은 출력값입니다.

이상으로 포스팅을 마치겠습니다.

C++ 값이 저장되어있는 배열에 최대값, 최소값 찾아내기

이번에 해볼 것은

어느 한 배열의 값이 저장되어있을 때,
그 배열의 최대값과 최소값을 찾아보는 것을 해보겠습니다.

지난 시간에도 살펴봤드시
배열은 하나하나! 다 해주어야합니다.

우선 랜덤함수를 써서 임의의 값들을 grade배열에 넣어주고
출력을 한번 해줍니다.

그리고 일단은 첫번째 배열 grade[0]을
최대값과 최소값이라고
뻥을 친 뒤!

for문을 써서 하나하나 조사해봅니다.

최대값 같은 경우에는
만약 최대값보다 큰 배열이 나타났다고 하면은
최대값은 그 배열로 바로 넣어줍니다.
최소값은 그 반대로!

그리고 최대값 최소값들을 출력해주면 되겠습니다.

 

이상으로 포스트를 마치겠습니다.

C++ 배열의 복사 및 확인

이번 시간에는
C++의 배열의 복사 및 확인을 해 볼 겁니다.
C와 거의 비슷합니다.

SIZE라는 기호상수를 10이라 지정을 해주고,
a 배열에 값을 하나하나 다 넣어 줍니다.

복사를 할 때 중요한 것은
값을 하나하나 다 직접!!

넣어주어야 합니다.

배열을 할 때는
반복문을 많이 만나 볼 수 있을 겁니다.

확인을 할때도 마찬가지!!
하나하나 직접
확인해야합니다.

적절한 if 문을 활용해서 말이죠

다음은 실행 화면입니다.





이만 포스팅을 마치겠습니다.

Chapter 1

Chapter 1. Parallel computing

Fundamental types of parallelism in application
l  Task parallelism : Distributing the task or functions
l  Data parallelism : Distributing the data across multiple cores
n  Block partitioning : Each thread takes one portion of the data
n  Cyclic partitioning : Each thread takes more than one portion of the data


image.png
n  Note. Distributing the data, I have to know How the data is stored physically and how the execution of each thread is ordered.(Computer architecture)
n  Note. The performance of a program is usually sensitive to the block size



Computer Architecture
l  Flynn’s Taxonomy that used classification scheme widely

n  SISD : A serial architecture, One core
n  SIMD : Multiple cores, Vector computer, Execute the same instruction stream, different data streams, most modern computers employ this. Writing code on the CPU, programmers can continue to think sequentially achieve parallel speed-up. Because the compiler takes care of the details
n  MISD : uncommon architecture.
n  MIMD : each executing independent instructions. Many MIMD architectures also include SIMD execution sub-components.
l  Advantage 3 objectives
n  Latency is the time it takes for an operation to start and complete
n  Bandwidth is the amount of data that can be processed per unit of time
n  Throughput is the amount of operations that can be processed per unit of time
l  GPU vs CPU
n  CPU core, relatively heavy-weight, is designed for very complex control logic, seeking to optimize the execution of sequential programs.
n  GPU core, relatively light-eight, is optimized for data-parallel tasks with simpler control logic, focusing on the throughput of parallel programs.
l  Heterogeneous computing
n  Using Different more than two device ex. CPU and GPU



n  GPU

C++ 배열을 이용하여 주사위 던져 숫자 몇 번 나오는지 횟수 세기

이번에는 배열을 이용하여 주사위를 던졌을 경우 각 숫자가 몇 번 나오는지 알아보는 것을 해보겠습니다. ​ ​   랜덤함수가 필요하기 때문에 ctime 헤더 파일을 넣어줍니다. FACES라는 기호상수에 6을 넣어줍니다.( ...