0

What will be the final value of variable sum?

Line-1: #include<stdio.h> Line-2: int main(){ Line-3: int cnt=1, sum=0, n=6; Line-4: while(cnt<=n){ Line-5: sum=sum+cnt; Line-6: ++cnt;} Line-7: printf("average=%f", sum/6.0); Line-8: return 0;}

17th Nov 2020, 8:58 PM
Ű¶Ű­Ù‰ .
2 Answers
+ 1
Check in the code playground..! Edit : if you don't understand what happening : sum = 1+2+3+4+5+6 = 21 Output : 21/6.0=> average=3.5
17th Nov 2020, 9:39 PM
Jayakrishna 🇼🇳
0
to print the average of the sum of 1 to n you can use (n(n+1)/2)/n => (n+1)/2
17th Nov 2020, 9:43 PM
KAWOTTE
KAWOTTE - avatar