I'm not sure what you are trying to do, but line 3 will never execute with your inputs, and you'll be stuck in an infinite loop when q and n become zero.
I get a general page fault on my computer, an intelĀ® processor, and would like to know if it generates any different result on any other PC.
This program performs integer division by zero (line 8, 5th iteration of the loop), and, that's what I observe on Linux/intel, Solaris/sparc, and AIX/power7.
The actual outputs:
$ ./test.linux.tsk
Floating point exception (core dumped)
$ ./test.sundev1.tsk
Arithmetic Exception
$ ./test.ibm.tsk
Trace/BPT trap (core dumped)
Bonus: valgrind on Linux says
==37064== Process terminating with default action of signal 8 (SIGFPE): dumping core
==37064== Integer divide by zero at address 0x521DD8F
==37064== at 0x804873C: f(int, int, int) (test.cc:8)
==37064== by 0x8048772: f(int, int, int) (test.cc:10)
==37064== by 0x8048772: f(int, int, int) (test.cc:10)
==37064== by 0x8048772: f(int, int, int) (test.cc:10)
==37064== by 0x8048772: f(int, int, int) (test.cc:10)
==37064== by 0x80487B2: main (test.cc:15)