1 / 6

(1) 369 게임 만들기 . 숫자를 입력 받아서 3,6,9 가 들어 있으면 개수대로 박수치기 ( 100 이하의 수 )

(1) 369 게임 만들기 . 숫자를 입력 받아서 3,6,9 가 들어 있으면 개수대로 박수치기 ( 100 이하의 수 ) < 예 > 36  박수짝짝 13  박수짝 int no_369, no_10 , no_1 , cnt =0; scanf (“%d”, &no_369); no_10 = no_369 ( ); // 입력 받은 수의 십의 자리 구하기 no_1 = no_369 ( ); // 일 의 자리 수 구하기

saeran
Télécharger la présentation

(1) 369 게임 만들기 . 숫자를 입력 받아서 3,6,9 가 들어 있으면 개수대로 박수치기 ( 100 이하의 수 )

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. (1) 369 게임 만들기 . 숫자를 입력 받아서 • 3,6,9가 들어 있으면 개수대로 박수치기 ( 100이하의 수) • <예> 36  박수짝짝13  박수짝 • int no_369, no_10 , no_1 , cnt=0; • scanf(“%d”, &no_369); • no_10 = no_369 ( ); //입력 받은 수의 십의 자리 구하기 • no_1 = no_369 ( ); //일의 자리 수 구하기 • if( no_10 == 3 || no_10 == 6 || no_10 == 9 ) • cnt++; //십의 자리에 있는 3,6,9 세기 • if( no_1 == 3 || no_1 == 6 || no_1 == 9 ) • cnt++; //일의 자리에 있는 3,6,9 세기 • if (cnt == 1 ) printf(“ 박수짝!”); • if (cnt == 2 ) printf(“ 박수짝짝!”);

  2. ( 2 ) 컴퓨터가 생각한 수 알아맞히기 • int com, num, find = 0, cnt=0; • com = rand() % 100 ; ( 0 ~ 99 ) //이 수를 알아맞히기 • while ( find != 1) { // find ==0 • scanf( “%d”, &num); • //입력 횟수를 셈 • if( com > num ) • printf(“? 수를 입력하세요!”); • else if ( com < num ) • printf(“ ?수를 입력하세요!”); • else find = ? ; • } //while 끝 • if ( find == ?) printf( “ %d 번 만에 맞추셨습니다”, cnt); • <입력횟수를 5회까지로 제한하는 것으로 바꾸기>

  3. <p89> 임의의 두 개의 서로 같지 않은, 1 부터 10 • 까지의 수 구하기 • int num1, num2; //변수 선언 • num1 = rand() % 10 + 1 ; //rand 함수 사용하여 수를 얻기 • num2 = rand() % 10 + 1 ; • while ( num1 == num2) { // num1 과 num2가 같으면 • 반복해서 새로운 수를 만들기 • num2 = rand() % 10 +1 ; • } • printf(“%d %d \n“, num1,num2);

  4. (3) 세 개의 서로 같지 않은, 1 부터 10 까지의 임의의 수 구하기 • int num1, num2, num3; • num1 = rand() % 10 + 1 ; • num2 = rand() % 10 + 1 ; • num3 = rand() % 10 + 1 ; • while ( ) • { • }

  5. < 원하는 숫자의 난수를 얻기 위한 방법> Rnadom r = new Random(); int num1 = r.nextInt(10); // 0 ~ 9 까지의 수 Rnadom r = new Random(); int num1 = r.nextInt(10); // 0 ~ 9 까지의 수 int num2 = r.nextInt(10); while (num1 == num2) { num2 = random.nextInt(10); } System.out.println(num1 + “ “ + num2);

  6. p100 4. 난수를 이용한 야구게임 (10 이하의 수) • 프로그램에서 3개의 서로 다른 난수를 발생시켜 기억시킨다. 2. 사용자로 부터3개의 서로 다른 수를 입력 받는다. 3. 난수와 사용자 입력 숫자를 비교하여 같은 번째가 일치하면 “스트라이크”, 다른 위치면 “볼”로 처리한다. 4. 3개의 숫자가 같은 위치에 모두 일치 하지 않으면 카운트를 출력하고 2번을 다시 수행한다. 5. 몇 회 만에 난수와 일치하는 수를 입력하였는지를 출력한다. [예] 난수4 8 1 사용자입력 8 1 3 출력 : 2 볼

More Related