Difference between revisions of "2022 Paper 1 Revision Quiz"
Line 69: | Line 69: | ||
{Look at this sample code: | {Look at this sample code: | ||
− | + | 1: public int Fact(int num) | |
− | 1: public int Fact(int num) | + | 2: { |
− | 2: { | + | 3: if (num == 0) |
− | 3: if (num == 0) | + | 4: return 1; |
− | 4: return 1; | + | 5: else |
− | 5: else | + | 6: return num * Fact(num-1); |
− | 6: return num * Fact(num-1); | + | 7: } |
− | 7: } | + | 8: |
− | 8: | + | 9:Fact(5); |
− | 9:Fact(5); | ||
The function Fact is run with the parameter of 5. | The function Fact is run with the parameter of 5. |