Ternary Operator

Lab C Beginner 10 points

Read two integers and print the smaller one and then the absolute difference, using the ternary operator ?:.

Input

Two integers.

Output

Two lines.

Example

Input

3 8

Output

3
5
Sample input available Sample output available
Editor
C

Hints

condition ? value_if_true : value_if_false

Solution explanation

The ternary operator is an expression, so it can be used in an assignment.

Show solution
#include <stdio.h>

int main() {
    int a, b;
    scanf("%d %d", &a, &b);
    int smaller = a < b ? a : b;
    int diff = a > b ? a - b : b - a;
    printf("%d\n%d\n", smaller, diff);
    return 0;
}
Output
Answer
HOME LEARN COMMUNITY DASHBOARD