English

Consider the following program segment in which the statements are jumbled. Choose the correct order of statements to calculate and return the factorial of 4. for (k=1; k

Advertisements
Advertisements

Question

Consider the following program segment in which the statements are jumbled. Choose the correct order of statements to calculate and return the factorial of 4.

for (k=1; k<=4; k++) →1
return fa;           →2
long fa = 1, k;      →3
fa*=k;               →4

Options

  • 1, 2, 3, 4

  • 3, 1, 4, 2

  • 3, 1, 2, 4

  • 1, 3, 2, 4

MCQ
Advertisements

Solution

3, 1, 4, 2

Explanation:

First, the variables are initialized. The loop then begins to calculate the factorial, where the value of k is repeatedly multiplied by the return variable fa. Finally, the computed value is returned.

shaalaa.com
  Is there an error in this question or solution?
2024-2025 (March) Official Board
Share
Notifications

Englishहिंदीमराठी


      Forgot password?
Use app×