#include int canreach(int dest, int a, int b, int c) { if(dest < 0) return 0; if(dest == 0) return 1; return (canreach(dest-a, a, b, c) + canreach(dest-b, a, b, c) + canreach(dest-c, a, b, c)); } int howtoreach(int dest, int a, int b, int c) { if(dest >= a && canreach(dest-a, a, b, c)) { printf("%d ", a); if(dest==a) return 1; else return (1 + howtoreach(dest-a, a, b, c)); } else if(dest >= b && canreach(dest-b, a, b, c)) { printf("%d ", b); if(dest == b) return 1; else return (1 + howtoreach(dest-b, a, b, c)); } else if(dest >= c && canreach(dest-c, a, b, c)) { printf("%d ", c); if(dest == c) return 1; else return (1 + howtoreach(dest-c, a, b, c)); } } int main() { int dest; int a, b, c; printf("Enter destination: "); scanf("%d", &dest); printf("Enter a,b,c: "); scanf("%d %d %d", &a, &b, &c); if(canreach(dest, a, b, c)) { printf("Destination reachable.\nSteps: "); printf("\nNumber of steps required: %d\n",howtoreach(dest, a, b, c)); } else printf("Destination not reachable.\n"); return 0; }