Computer Science, asked by keerthik75, 6 months ago

N= int(input(“Enter N:”))

i=1

sum=0

while i<N :

if i %2 ==0:

sum=sum+1

i= i+ 1

print(sum)

a. What is the output when the input value is 8?​

Answers

Answered by alanbaiju103094
0

Answer:

(a)

int i = 1;

while (i < 10)

if (i % 2 == 0)

System.out.println(i);

(b)

int i = 1;

while (i < 10)

if (i % 2 == 0)

System.out.println(i++);

(c)

int i = 1;

while (i < 10)

if ((i++) % 2 == 0)

System.out.println(i)

Explanation:

(a) Infinite number of times.

(b) Infinite number of times.

(c) The loop body is executed nine times. The output is 3, 5, 7, 9 on separate lines.

Answered by DarkShadow040
0
The output would be 3

Explanation:

When i = 1
1<8 —> True
But 1%2 is not 0 meaning 1 divided by 2, the remainder is not 1


When i = 2
2<8. —> True
Now 2%2 is 0
So sum which was sum+ 1 is updated to 0 + 1 = 1

When i = 3
3<8 —> True
Now 3%2 is not 0

So basically when the number is divided by 2 and remainder is 0, sum gets increased by 1 but remainder is not 0, sum is not increased


Similarly till i=7 the condition is checked

But when i = 8,
8<8 —> False

So the program stops there

Hope this helps you :)
Please Mark this answer brainliest


Similar questions