1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #define _CRT_SECURE_NO_WARNINGS #include <stdio.h> #include <stdlib.h> #include <time.h> int main(void) { int answer; // Á¤´ä int guess; int tries = 0; srand(time(NULL)); answer = rand()% 100; // ¹Ýº¹ ±¸Á¶ do { printf("Á¤´äÀ» ÃßÃøÇÏ¿© º¸½Ã¿À: "); scanf("%d", &guess); tries++; if (guess >answer) // »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ Á¤¼ö°¡ Á¤´äº¸´Ù ³ôÀ¸¸é printf("Á¦½ÃÇÑ Á¤¼ö°¡ ³ô½À´Ï´Ù.\n"); if (guess <answer) // »ç¿ëÀÚ°¡ ÀÔ·ÂÇÑ Á¤¼ö°¡ Á¤´äº¸´Ù ³·À¸¸é printf("Á¦½ÃÇÑ Á¤¼ö°¡ ³·½À´Ï´Ù.\n"); } while (guess !=answer); printf("ÃàÇÏÇÕ´Ï´Ù. ½ÃµµÈ½¼ö=%d\n", tries); return 0; } | cs |