Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3694918
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T04:33:16+00:00 2026-05-19T04:33:16+00:00

if anyone could answer me why this works, it would be greatly appreciated. The

  • 0

if anyone could answer me why this works, it would be greatly appreciated. The exercise (chapter 4, ex 7 and 8) says that if you have the expression:
9 – ((total – 1) % 10)
then, you could be tempted to simplify it like this:
10 – (total % 10)
But this would not work. Instead he offers the alternative:
(10 – (total % 10)) % 10

Now, I understand how he got to the first simplification, but not why it’s wrong, or why does the second one works.

Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T04:33:17+00:00Added an answer on May 19, 2026 at 4:33 am

    Consider the outputs for total = 10 to see that the second expression is not equivalent.

    Note also that the third expression is not equivalent to the first expression unless total > 0 (because the behaviour of % is implementation-defined in pre-C99 C, and defined but not what you want in C99).

    Assuming that total > 0, the first and third expressions are equivalent due to the following mathematical identity:

    (a % b) == (((a + c) % b) - c) % b
    

    To understand why, imagine doing the operations on a clock-face.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If anyone could recommend a good book for learning mySQL as well, that would
Like the title says, if anyone has the answer I would like to know.
Before you answer this I have never developed anything popular enough to attain high
was wondering if anyone could help me out. I have been looking all over
i'm relatively new to this and was wondering if anyone could point me in
OK, this feels like a question that should be easy to answer, but as
I was wondering whether anyone could assist me. When the user clicks the menu
I was wondering if anyone could instruct as how to replace hyperlinks with their
I was wondering if anyone could help me implement color selection in my iOS
I was wondering if anyone could tell me about the i++ operator in C#.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.