Multiple choice

void main() { int i,n,sum=0; scanf(“%d”,&n); for(i=0;i<=n;i++) sum=sum+i; printf(“%d”,sum); } The above program is for sum of the numbers from 0 to n. What is the maximum value of n for which the program gives the desired output?

  1. 922

  2. 32767

  3. 923

  4. 999

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

The sum from 0 to 922 is 32287. If 923 is added with 32287, the sum will be 33210, which is outside the range of integer data type. Hence, n up to 922 can give the desired output.