Computer Science, asked by roop28, 1 year ago

please solve this give me output for this

Attachments:

Answers

Answered by Anonymous
1

Hi,

Please check screenshot for output:

Here I want to show you what actually is inside those varuables.

sum(0) = sum (0) + a (1)

sum (1) = sum (1) + a (3)

sum (4) = sum 4 + a (5)

sum (9) = sum (9) + a (7)

sum (16) = sum (16) + a (9); ( $a<=8 condition will fail here because a is greater than 8)

sum (16)

a (9)

Attachments:

nitish8089: i have two page view and here all want's proof of output
nitish8089: biggest problem
nitish8089: helli
nitish8089: *hello
Answered by nitish8089
2
output:
16
9
as you are get after the for loop there is no braces so only one statement run ...
$Sum=$Sum+$a..
and a values..
a=1
a=3
a=5
a=7
and for the value of a=9
the loop will not execute further so
$Sum=1+3+5+7
$Sum=16
$a=9

nitish8089: i know i will tell out the only first statement run 5 times
nitish8089: not echo statement run
nitish8089: for this we have to wrap the code by braces
nitish8089: ya!!! it's confusing as i know all language support this format of loop
nitish8089: ya!! it's not good practice.... to write code like this
Similar questions