201k views
4 votes
Consider the following C program. #include int main(void) a- What is the output if the input i = 9? b- What is the output if the input i = 151?

User XCeptable
by
5.4k points

1 Answer

2 votes

Answer:

When i=9 it is 90, when i=151 it is 25.

Step-by-step explanation:

The program asks the user to enter the value of the i. Then, i is checked. If i is greater than 10 or smaller than or equal to 99, the value of the equation, (i-i/10*10)*10+i/10), is printed. Otherwise, "out of range" is printed.

For i=9, since the value is smaller than or equal to 99, the if part will be executed. If you substitute 9 for the i in the equation, the output will be 90.

→ (9-9/10*10)*10+9/10) (Since both numbers are integers in 9/10, it is 0, not 0.9)

→ (9-0*10)*10+0)

→ (9)*10

→ 90

For i=151, since the value is greater than 10, again the if part will be executed. If you substitute 151 for the i in the equation, the output will be 25.

→ (151-151/10*10)*10+151/10) (Since both numbers are integers in 151/10, it is 15, not 15.1)

→ (151-15*10)*10+15)

→ (151-150)*10+15)

→ 1*10+15

→ 25

User Tunarob
by
5.5k points