The C code is as follows:
1#include <stdio.h>2 3 intFunc1 (intN)4 {5 return 1<<N;6 }7 8 intFunc2 (intN)9 {Ten One if(n==0) A { - return 1; - } the - returnFUNC2 (n1)*2; - } - + intFUNC3 (intN) - { + intC=1, I; A for(i=0; i<n; i++) at { -c*=2; - } - - returnC; - } in - to intMainvoid) + { - intn=Ten; the *printf"Func1 calculates 2 of%d times as:%d\n", N, func1 (n)); $printf"Func2 calculates 2 of%d times as:%d\n", N, Func2 (n));Panax Notoginsengprintf"Func3 calculates 2 of%d times as:%d\n", N, func3 (n)); - theSystem"Pause"); + return 0; A}
Run after compiling in the dev C + + environment with the following output:
FUNC1 calculates 2 of the 10-time Square: 1024
FUNC2 calculates 2 of the 10-time Square: 1024
FUNC3 calculates 2 of the 10-time Square: 1024
Please press any key to continue ...
Three ways to calculate the n-th 2 (C language Implementation)