:: 게시판
:: 이전 게시판
|
이전 질문 게시판은 새 글 쓰기를 막았습니다. [질문 게시판]을 이용바랍니다.
통합규정 1.3 이용안내 인용"Pgr은 '명문화된 삭제규정'이 반드시 필요하지 않은 분을 환영합니다.법 없이도 사는 사람, 남에게 상처를 주지 않으면서 같이 이야기 나눌 수 있는 분이면 좋겠습니다."
07/11/05 07:04
혼자 열심히 한 끝에 성공했네요. #include <stdlib.h>
#include <stdio.h> #include <time.h> void main(void) int i, j=0; double temp; int number; srand( (unsigned)time( NULL ) ); while(1) { temp=rand(); temp/=RAND_MAX; number=temp*200; if (j == 0) { if (number == 71) { printf("%c", number); j++; } if (j == 1) if (number == 79) { printf("%c", number); j++; } if (j == 2) if (number == 79) { printf("%c", number); j++; } if (j == 3) if (number == 68) { printf("%c\n", number); break; } } } 더 좋은 방법이 있다면 알려주시면 감사하겠습니다^^
07/11/05 12:43
char pick_Good(int asc)
double temp; int number; while(1) { temp=rand(); temp/=RAND_MAX; number=temp*200; if (number == asc) { break; } return number; //여기서 number를 리턴할때 char형으로 바꿔서 넘겨주세요. } void main() char str[5]; str[0] = pick_Good(71); str[1] = pick_Good(79); str[2] = pick_Good(79); str[3] = pick_Good(68); str[4] = '\0'; // 맞는지 안맞는지;; 배열 뒤에 저거 붙여줘야 하나요? printf("랜덤 함수 = %s", str);
07/11/05 12:45
제가 요즘 자바만 해서 C문법을 잘 모르겠습니다.
number리턴할때 정수를 char형으로 캐스팅해서 리턴해주시고 str[4]에서 배열 끝에 널값 넣어주세요. 돌아갈지는 잘모르겠지만 함수를 사용하면 좀 더 깔끔해진답니다.
|