One thing you can do that I find comes up pretty often in C is start using switch statements to avoid code duplication. Because your operators all take 2 numbers, you’ve separated out the input handling into its own block; that alone is a really good insight.
You can take it another step further by making your print statement also, mostly, one block of code, with the only difference being the operation being preformed. By printing “The” followed by using an if-else block — or, again, preferably a switch statement — to both print the operation text, and compute memory, you can print the remainder of the line the same way for every operation.
It may seem nitpicky for such a simple program; but the use case of C is for programs which require tight execution and often contain complex, low-level logic. Reducing complexity whenever possible helps make C more readable, as well as signal when the complexity is necessary.
The same person as Daedskin@lemm.ee and Daedskin@programming.dev
- 0 Posts
- 2 Comments
Joined 9 months ago
Cake day: June 26th, 2025
You are not logged in. If you use a Fediverse account that is able to follow users, you can follow this user.


I thought I might have as well, but then I realized repeating the question word-for-word is there to help rule that out. It’s not fool-proof, but a human would be a lot less likely to fall for it when reading the question with the explicit intent to make sure they don’t miss, add, or misread any words.