<<열혈강의 C 도전 프로그래밍 THREE 3장 솔루션>>열혈강의 C,도전 프로그래밍,문제풀이,솔루션,소스코드,결과,프로그래밍 문제,주석,해설,프로그래밍 3
본 자료는 4페이지 의 미리보기를 제공합니다. 이미지를 클릭하여 주세요.
닫기
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
해당 자료는 4페이지 까지만 미리보기를 제공합니다.
4페이지 이후부터 다운로드 후 확인할 수 있습니다.

소개글

<<열혈강의 C 도전 프로그래밍 THREE 3장 솔루션>>열혈강의 C,도전 프로그래밍,문제풀이,솔루션,소스코드,결과,프로그래밍 문제,주석,해설,프로그래밍 3에 대한 보고서 자료입니다.

목차

도전 프로그래밍 THREE

본문내용

= 0; j < num2; j++)
{
printf("%4d", snail_arr[i][j]);
}
printf("\n");
}
return 0;
}
- 결과
도전 3
- 소스코드
#include
#include
int main(void)
{
int i;
printf("난수의 범위 : 0부터 %d까지 \n", RAND_MAX);
for (i = 0; i < 5; i++)
{
printf("난수 출력: %d \n", rand() % 100);
// 난수를 100으로 나눈 나머지는 100을 넘지 않으므로 %연산자 사용
}
return 0;
}
- 결과
도전 4
- 소스코드
#include
#include
#include
int main(void)
{
int i;
int dice1 = 0, dice2 = 0;
srand((int)time(NULL));
while (dice1 == 0 || dice2 == 0)// 1~6 까지 범위를 지정해주기 위한 반복문
{
dice1 = rand() % 7;
dice2 = rand() % 7;
}
printf("주사위 결과 : %d, %d \n", dice1, dice2);
return 0;
}
- 결과
도전 5
- 소스코드
#include
#include
#include
int victory = 0, tie = 0;// 성적 스코어
void my_choice_print(int val)// 나의 선택 출력
{
if (val == 1) printf("당신은 가위 선택, ");
else if (val == 2) printf("당신은 바위 선택, ");
else printf("당신은 보 선택, ");
}
void com_choice_print(int val)// 컴퓨터의 선택 출력
{
if (val == 1) printf("컴퓨터는 가위 선택, ");
else if (val == 2) printf("컴퓨터는 바위 선택, ");
else printf("컴퓨터는 보 선택, ");
}
int result(int me, int com)// 결과값 분석
{
if (me == com)// 비겼을 경우
{
printf("비겼습니다. \n");
tie++;
return 0;
}
if (me == 1)// 내가 가위를 낸 경우
{
if (com == 2)
{
printf("졌습니다. \n");
return 1;
}
else
{
printf("이겼습니다. \n");
victory++;
return 0;
}
}
if (me == 2)// 내가 바위를 낸 경우
{
if (com == 1)
{
printf("이겼습니다. \n");
victory++;
return 0;
}
else
{
printf("졌습니다. \n");
return 1;
}
}
if (me == 3)// 내가 보를 낸 경우
{
if (com == 1)
{
printf("졌습니다 \n");
return 1;
}
else
{
printf("이겼습니다. \n");
victory++;
return 0;
}
}
}
int main(void)
{
int my_choice, com_choice;
int defeat_flag = 0;// 패배했을 경우 표시
srand((int)time(NULL));
while (defeat_flag != 1)
{
printf("바위는 1, 가위는 2, 보는 3 :");
scanf_s("%d", &my_choice);
if (my_choice == 0 || my_choice > 3)
{
printf("1~3 중의 숫자를 눌러주세요 \n");
continue;
}
com_choice = (rand() % 3) + 1;
my_choice_print(my_choice);
com_choice_print(com_choice);
defeat_flag = result(my_choice, com_choice);
}
printf("게임의 결과 : %d승 %d무 \n",victory, tie);
return 0;
}
- 결과
도전 4
- 소스코드
#include
#include
#include
int main(void)
{
int com_val[3] = { 0 }, my_val[3];
int i, j, x;
int strike = 0, ball = 0;
int pass_flag = 0;
srand((int)time(NULL));
while (com_val[0] == com_val[1] || com_val[1] == com_val[2] || com_val[1] == com_val[3])
// 컴퓨터가 서로 다른 숫자를 뽑을 때 까지 반복
{
for (i = 0; i < 3; i++)
{
com_val[i] = rand() % 10;
}
}
printf("Start Game ! \n \n \n");
x = 0;
while (pass_flag == 0)// 합격할 때까지 반복
{
//printf("컴퓨터 숫자 확인 %d %d %d \n", com_val[0], com_val[1], com_val[2]) // 정답 확인용 코드
printf("3개의 숫자 선택 :");
scanf_s("%d %d %d", &my_val[0], &my_val[1], &my_val[2]);
for (i = 0; i < 3; i++)
// 차례대로 비교해서 값이 같으면 ball 증가, 그런데 위치까지 같으면 ball 증가 취소하고 strike 증가
{
for (j = 0; j < 3; j++)
{
if (com_val[i] == my_val[j])
{
ball++;
if (i == j)
{
ball--;
strike++;
}
}
}
}
printf(" %d 번째 도전결과 : %d strike, %d ball!! \n", x++, strike, ball);
if (strike == 3)
{
printf("Game End! \n");
pass_flag = 1;
}
strike = 0; ball = 0;
}
return 0;
}
- 결과
  • 가격2,000
  • 페이지수14페이지
  • 등록일2016.03.07
  • 저작시기2016.3
  • 파일형식한글(hwp)
  • 자료번호#995861
본 자료는 최근 2주간 다운받은 회원이 없습니다.
청소해
다운로드 장바구니