# TCS Programming Questions on Functions and Scope – 1

1.Choose the correct answer Saumya writes a code which has a function which calls itself. Which programming concept is Saumya using?
a. This is bad programming practice and should not be done.
b. Recursion
c. Decision Making

2. Consider the following function function calculate( n ) { if(n equals 5) return 5 else return (n + calculate(n-5)) end } Shishir calls the function by the statement, calculate(20). What value will the function return?
a. 50
b. 200
c. 35
d. 20

3. Choose the correct answer function g(int n) { if (n > 0) return 1; else return -1; } function f(int a, int b) { if (a > b) return g(b-a); if (a < b) return g(a-b); return 0; } If f(a,b) is called, what is returned?
a. Always -1
b. 1 if a > b, -1 if a < b, 0 otherwise
c. -1 if a > b, 1 if a < b, 0 otherwise
d. 0 if a equals b, -1 otherwise

4.Choose the correct answer Afzal writes a piece of code, where a set of three lines occur around 10 times in different parts of the program. What programming concept can he use to shorten his program code length?
a. Use for loops
b. Use functions
c. Use arrays
d. Use classes