How do I write a c program only using getchar and putchar to have it work like a basic calculator?

1 answer

Answer

1260299

2026-05-01 05:15

+ Follow

To create a basic calculator in C using only getchar and putchar, you'll need to read characters one at a time to capture numbers and operators. Store the first number, then read the operator, followed by the second number. Perform the calculation based on the operator you read, and finally, use putchar to display the result. Note that this approach will be limited to single-digit integers and basic operations due to the restrictions of using only these two functions.

ReportLike(0ShareFavorite

Copyright © 2026 eLLeNow.com All Rights Reserved.