int fun(int n) { int i, j, sum = 0; for(i = 1;i<=n;i++) for(j=i;j<=i;j++)…

int fun(int n)

{

int i, j, sum = 0;

for(i = 1;i<=n;i++)

for(j=i;j<=i;j++)

sum=sum+j;

return(sum);

}

int main()

{

printf("%d", fun(15));

getchar();

return 0;

}

Answer: A. 120Output: 120 Explanation: The function fun(n) has two nested loops. The outer loop runs from i = 1 to n. The inner loop runs from j = i to j = i, which means…

  1. A.

    120

  2. B.

    15

  3. C.

    100

  4. D.

    115

Attempted by 453 students.

Show answer & explanation

Correct answer: A

Output: 120

Explanation: The function fun(n) has two nested loops. The outer loop runs from i = 1 to n. The inner loop runs from j = i to j = i, which means it executes exactly once for each i, adding i to the sum. Therefore, the total sum is the sum of integers from 1 to n, which is given by the formula n(n+1)/2. For n = 15, the result is 15×16/2 = 120.

Explore the full course: Coal India Management Trainee

Loading lesson…