아래 코드에서 for문 마지막 값만 출력하고 싶습니다.
조회수 1719회
#pragma warning(disable:4996)
#include<stdio.h>
int main(void) {
int cnt = 0, digt_cnt = 0, i, total = 0;
char c;
while (c = getchar()) {
if (c == 'q')
return 0;
++cnt;
{if (c >= '0' && c <= 9) ++digt_cnt;
i = 1;
while (i++ <= c) {
if (c == "B")
break;
total += 1;
printf("input = %c and total = %d\n", c, total);
}
}
return 0;
}
}
문자를 입력하면 아스키 코드 값이 출력되는 프로그램입니다. 다만 출력될때 예를 들어 A를 입력하면
input = A and total = 1
input = A and total = 2
input = A and total = 3
..........
input = A and total = 65
라고 나옵니다. 마지막 값만 출력하고 싶은데 어떻게 해야 할까요?
-
(•́ ✖ •̀)
알 수 없는 사용자
1 답변
-
while (i++ <= c) { if (c == "B") break; total += 1; printf("input = %c and total = %d\n", c, total); }
= >
while (i++ <= c) { if (c == "B") break; total += 1; } printf("input = %c and total = %d\n", c, total);
이러면 될듯 하네요.
-
(•́ ✖ •̀)
알 수 없는 사용자
-
댓글 입력