코락 CoRock
코딩하는 락스타
코락 CoRock
  • 분류 전체보기 (393)
    • frameworks (19)
      • spring (19)
      • spring-boot (0)
      • testing (0)
    • languages (94)
      • java (39)
      • kotlin (0)
      • python (42)
      • r (13)
    • libraries (0)
    • programming (239)
      • android (13)
      • c (17)
      • cpp (22)
      • database (18)
      • design-pattern (4)
      • data-structures (11)
      • git (8)
      • hadoop (6)
      • html-css (7)
      • issue (4)
      • javascript (26)
      • jsp (34)
      • os (29)
      • php (6)
      • preferences (19)
      • etc (15)
    • discography (37)
      • k-pop (18)
      • pop (19)
    • blog (3)

블로그 메뉴

  • Programming
  • Java
  • JavaScript
  • Discography
  • K-Pop Songs
  • Pop Songs
  • Blog
  • Guestbook

공지사항

인기 글

태그

  • 자바스크립트
  • CentOS
  • Spring
  • jsp
  • Android
  • 파이썬
  • linux
  • r
  • python
  • oracle
  • Java
  • javascript

최근 댓글

최근 글

티스토리

반응형
hELLO · Designed By 정상우.
코락 CoRock

코딩하는 락스타

languages/java

[DAY 04] 계산기 프로그램 구현

2018. 1. 22. 23:47
반응형
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
 
void main()
{
    int num1, num2;
    char oper;
 
    printf("Enter the 1st number : ");
    scanf("%d", &num1);
    printf("Enter operator : ");
    scanf("%c", &oper);
    printf("Enter the 2nd number : ");
    scanf("%d", &num2);
 
    printf("%d %c %d = %d \n", num1, oper, num2, num1 + num2);
}
Colored by Color Scripter
cs


operator의 문제점


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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
 
int main(void)
{
    int x, y;
    char oper;
    char select;
 
    do {
        printf("Input the 1st value : ");
        scanf("%d", &x);
 
        printf("Input operator(+, -, *, /) : ");
        rewind(stdin);
        scanf("%c", &oper);
 
        printf("Input the 2nd value : ");
        scanf("%d", &y);
 
        switch (oper)
        {
        case '+':
            printf("result = %d %c %d = %d \n", x, oper, y, x + y);
            break;
        case '-':
            printf("result = %d %c %d = %d \n", x, oper, y, x - y);
            break;
        case '*':
            printf("result = %d %c %d = %d \n", x, oper, y, x * y);
            break;
        case '/':
            printf("result = %d %c %d = %.2f \n", x, oper, y, (float)x / y);
            break;
        default:
            puts("You entered wrong operator!");
            break;
        }
 
        printf("Do you want to continue? : ");
        rewind(stdin);
        scanf("%c", &select);
    } while (select == 'Y' || select == 'y');
 
    return 0;
}
Colored by Color Scripter
cs



반응형
저작자표시 비영리 변경금지 (새창열림)
    'languages/java' 카테고리의 다른 글
    • [Java] 예외처리
    • [Java] 제네릭과 컬렉션
    • [Java] 내부 클래스
    • [Java] class(추상화)
    코락 CoRock
    코락 CoRock
    A COder dreaming of being a ROCKstar

    티스토리툴바