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. 120 — 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…
- A.
120
- B.
15
- C.
100
- D.
115
Attempted by 455 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.