Computer Science, asked by aliabbas2603, 1 year ago

Find the output:
N= int (input (“Enter N:”))
i=1
Sum=0
while i if i % 2==0:
Sum= Sum + i
i=i +1
print (Sum)

Answers

Answered by diptianandpara92
4

Answer:

Sum = Sum + i

= 0+ 1

= 1

i= i + 1

= 1+ 1

= 2

Hope this helps you....

Answered by Tulsi4890
2

The correct question is

Find the output:

N = int(input ( "Enter N:" ))

i = 1

Sum = 0

for i in range (1, N) :

if i % 2 == 0 :

Sum = Sum + i

i = i + 1

print(Sum)

The required answer is "For every value of 'i' in range 1 to N if 'i' is an even number then the even number modulus of 2 is always '0' so, it enters the if function command and the even value 'i' is incremented to the sum and this is continued till 'i' is out of the range".

We are required to find the output of the following program code.

  • In this code, the first line was about to get N as input in integer and given a value for 'i' as "1" in the second line and given value for "sum" as "0".
  • In the 4th statement for statement is included for the range 1 to N values
  • In the 5th statement 'if' statement for 'i' modulus of '2' is included inside the for statement.
  • In the 6th statement, the 'sum' value is incremented by 'i' inside the 'if' function
  • In the 7th statement, the 'i' value is incremented by 1
  • Finally, In the 8th statement, the 'sum' is printed outside of the while statement.

The given code runs and gives the output as,

For every value of 'i' in range 1 to N if 'i' is an even number, it enters the if function command and the value 'i' is incremented to the sum and this is continued till 'i' is out of the range.

Example: The output

"Enter N:5

6"

In the above output as an example, for 'i' in ranges 1,2,3,4 even 'i' values are added and printed as output. 2 and 4 are the even 'i' values, and the sum = 2+4

       = 6

So, The output is 6.

#SPJ2

Similar questions