scanf("%d", &num);
You're missing that &. The & gives the address of a variable. scanf needs the address of num, so it knows where to store the number it read in from the user.