Divide Two Numbers Using Long Division
C

Not exactly a long division - this answer uses the method used in the real old days.

#include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;
int main() {
    int a,b;
    scanf("%d %d", &amp;a, &amp;b);
    int *p=calloc(b, sizeof(int));
    int *q=p;
    while(a--) {
        (*p)++;
        if(p-q&lt;b-1) p++;
        else p-=b-1;
    }
    p=q;
    int r=0, i;
    for(i=0; i&lt;b; i++) r+=p[i]-p[b-1];
    printf("%d %d\n", p[b-1], r);
    return 0;
}


Explanation:

Suppose you are given a number of sheep and you need to split them up into b number of groups. The method used here is to assign each sheep into a different group until the total number of groups reaches b, then start from the first group again. This repeats until there are no more sheep. Then, the quotient will be the number of sheep in the last group, and the remainder will be the sum of the differences between each group and the last group.

An illustration for 8/3:

       |Group 1 | Group 2 | Group 3
-------------------------------------
       | 1      | 2       | 3        // first sheep in group 1, second sheep in group 2, etc
       | 4      | 5       | 6
       | 7      | 8       |
-------------------------------------
total: | 3      | 3       | 2


So the quotient is 2 and the remainder is (3-2)+(3-2)=2.