본문 바로가기

728x90

printf

(12)
C언어 게임 아빠는 대머리 ... #include #include int main(void) { srand(time(NULL)); printf("\n\n == 아빠는 대머리 게임 == \n\n"); int answer; int treatment = rand() % 4; int cntShowBottle = 0; // 이번 게임에 보여줄 병 갯수 int prevCntShowBottle = 0; // 앞 게임에 보여준 병 갯수 //서로 보여준 병 갯수를 다르게 하여 정답률 향상 (처음에 2개 -> 다음에 3개) //3번의 기회 (3번의 발모제 투여 시도) for (int i = 1; i 2 ~ 3 } while (cntShowBottle == prevCntShowBottle); prevCntShowBottle = cntShowBottle; i..
C언어 && || 연산법 #include int main(void) { //&& || 연산법 int a = 10; int b = 10; int c = 12; int d = 12; if (a == b && c == d) { printf("a와 b는 같고 c와 d도 같습니다\n"); } else { printf(" 값이 서로 다릅니다.\n"); } } ​ ​
C언어 반복문 별찍기... #include int main(void) { /* * ** *** **** ***** */ for (int i = 0; i < 5; i++) { for (int j = 0; j
C언어 기초 a++, ++a #include int main(void) { int a = 10; printf("a는 %d\n", a); a++; printf("a는 %d\n", a); a++; printf("a는 %d\n", a); int b = 20; printf(" b는 %d\n", ++b); printf(" b는 %d\n", b++); printf(" b는 %d\n", b); return 0; } 결과... ​
C언어 Scanf 문자열 입출력... #include int main(void) { char str[256]; scanf_s("%s", str, sizeof(str)); printf("%s", str); return 0; } ​ 결과 ​ ​ 입력하는 문자열을 띄어쓰기 하면 출력이 안됨 ​ 문자열을 입력
C언어 기초 Scanf / printf 관련 간단 프로젝트 #include int main(void) { // 프로젝트 // 경찰관이 범저좌의 정보를 입수 (조서 작성) // 이름? 나이? 몸무게? 키? 범죄명 char name[25]; printf("이름이 뭐에요?"); scanf_s("%s", name, sizeof(name)); int age; printf("몇 살이에요?"); scanf_s("%d", &age); float weight; printf("몸무게는 몇kg 이에요?"); scanf_s("%f", &weight); double height; printf("키는 몇 cm 이에요?"); scanf_s("%lf", &height); char what[256]; printf("무슨 범죄를 저질렀어요?"); scanf_s("%s", what, sizeof..
C언어 문자 출력하기 기초 #include int main(void) { // 문자(한 글자), 문자열 (한 글자 이상의 여러글자) int c = 'A'; printf("%c\n", c); return 0; } ​ 결과 ​
C언어 scanf 예제#2 #include int main(void) { int one, two, three; printf("3개의 정수를 입력하시오 : "); scanf_s("%d %d %d", &one, &two, &three); printf("첫번째 값: %d\n", one); printf("두번째 값: %d\n", two); printf("세번째 값: %d\n", three); return 0; } ​ 결과 ​

728x90