All pastes #923684 Raw Edit

Someone

public c v1 · immutable
#923684 ·published 2008-02-29 19:33 UTC
rendered paste body
#include <stdio.h>#include <string.h>#include <stdlib.h>void hanoi(int disks, char tower_from, char tower_to, char tower_help, size_t r) {        char * tabs = calloc(r + 1, sizeof(char));        size_t i = r;        while (i--) strcat(tabs, "\t");        if(disks==1) {                printf("%s(%d) %d->%d.\n",tabs,disks,tower_from,tower_to);                return;        }        else {                hanoi(disks-1, tower_from, tower_help, tower_to, r + 1);                printf("%s(%d) %d->%d.\n",tabs,disks, tower_from,tower_to);                hanoi(disks-1, tower_help, tower_to, tower_from, r + 1);        }}int main(void) {        int disks;        printf("Enter no of disks: ");        scanf("%d",&disks);        hanoi(disks, 1, 3, 2, 0);        return 0;}