Challenge: Quotient and Remainder

Lab C Beginner 10 points

Write void divide(int a, int b, int *quotient, int *remainder) that fills in both results. Read a and b (b is never 0), call it, and print Q R.

Input

Two integers a and b.

Output

The quotient and remainder separated by a space.

Example

Input

17 5

Output

3 2
Sample input available Sample output available
Editor
C

Hints

Inside the function, write the results with *quotient = ... and *remainder = ...

In main, pass &q and &r.

Solution explanation

Passing addresses lets one function hand back two answers.

Show solution
#include <stdio.h>

void divide(int a, int b, int *quotient, int *remainder) {
    *quotient = a / b;
    *remainder = a % b;
}

int main() {
    int a, b, q, r;
    scanf("%d %d", &a, &b);
    divide(a, b, &q, &r);
    printf("%d %d\n", q, r);
    return 0;
}
Output
Answer
HOME LABS COMMUNITY DASHBOARD