본문 바로가기

프로그래밍 언어들/C 문제풀이

C언어 문제 - 점수를 입력받아 학점 출력하기(switch~case문) (questions in C) C언어 문제 - (questions in C) - switch~case 문을 이용하여 점수(0~100)를 입력받아 90~100이면 A, 80~89면 B, 70~79면 C이고 나머지는 F를 출력하라. (단, case 문은 5개 이하만 사용할 것) #include int main (void) { int score; scanf("%d", &score); switch(score/10) { case 10: case 9: printf("A\n"); break; case 8: printf("B\n"); break; case 7: printf("C\n"); break; default: printf("F\n"); } } 더보기
C언어 문제 - 세 정수 중 가장 큰 수(최대값) 출력하기 (questions in C) C언어 문제 - (questions in C) - 세 정수를 입력받아 가장 큰 수(최대값)를 출력하라. #include int main (void) { int x, y, z; int max; scanf("%d%d%d", &x, &y, &z); max = x; if( max z) { max = y; } else { max = z; } } else { if( max 더보기
C언어 문제 - 짝수 또는 홀수 판단하기 (questions in C) C언어 문제 - (questions in C) - 입력받은 수가 홀수 또는 짝수인지 판단하여 출력하라. #include int main (void) { int n; scanf("%d", &n); if( n % 2 == 0) { printf("짝수\n"); } else { printf("홀수\n"); } } 더보기
C언어 문제 - 점수를 입력받아 학점 출력하기 (questions in C) C언어 문제 - (questions in C) - 0~100 사이의 점수를 입력받아 90~100 사이면 A, 80~89 사이면 B, 70~79 사이면 C, 60~69 사이면 D, 나머지는 F를 출력하라. #include int main (void) { int score; scanf("%d", &score); if( score >= 90 && score = 80 && score = 70 && score = 60 && score 더보기
C언어 문제 - 마이너스(-) 연산자 없이 뺄셈 하기 (questions in C) C언어 문제 - (questions in C) - 마이너스(-) 연산자 없이 뺄셈 하기 #include int main (void) { int n; int m; scanf("%d", &n); scanf("%d", &m); m = ~m + 1; printf("%d\n", n + m); } 더보기
C언어 문제 - 거스름돈 계산 (questions in C) C언어 문제(questions in C) - 물건 가격과 지불 금액을 입력받고, 거스름돈에 대해서 5000원, 1000원, 500원, 100원, 10원, 1원을 각각 얼마씩 줘야하는지 계산하기. #include int main (void) { int cost; int pay; int money; scanf("%d", &cost); scanf("%d", &pay); money = pay - cost; printf("5천원 %d장\n", money / 5000); money = money % 5000; printf("1000원 %d장\n", money / 1000); money = money % 1000; printf("500원 %d개\n", money / 500); money = money % 500; p.. 더보기
C언어 문제 - 입력받은 세 자리 수 거꾸로 출력 (questions in C) C언어 문제(questions in C) - 입력받은 세 자리 수 거꾸로 출력 #include int main (void) { int number; int result; scanf("%d", &number); result = number / 100; result += ((number % 100) / 10) * 10; result += (number % 10) * 100; printf("%d\n", result); //printf("%d%d%d\n", number % 10, (number % 100) / 10, number / 100); } 더보기