minseo-jung / study-c

0 stars 0 forks source link

두 개의 정수를 받아서 두 수의 차 구하기 #5

Closed minseo-jung closed 5 years ago

minseo-jung commented 5 years ago
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void p8_1_2()
{
    int a, b;
    printf("두 숫자를 입력하세요 ex 4 5\n");
    scanf("%d %d", &a, &b);
    if (a > b)

        printf("%d", a - b);
    else
        printf("%d", b - a);

    return 0;

}
minseo-jung commented 5 years ago

변형

#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void p8_1_2()
{
    int a, b;
    int c = 0;
    printf("두 숫자를 입력하세요 ex 4 5\n");
    scanf("%d %d", &a, &b);

    c = (a < b) ? b - a : a - b;

    printf("%d\n", c);

    return 0;

}