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 9152469
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T12:03:17+00:00 2026-06-17T12:03:17+00:00

Let’s say I am given integers x and y (satisfying x <= y with

  • 0

Let’s say I am given integers x and y (satisfying x <= y with ones digit of 0 so they are, in particular, divisible by two). Then I know that their average avg = ((x+y) / 2) is an integer as well. I would like to find this midpoint rounded up to a resolution of 100. In other words if my two inputs are 75200 and 75300 then the avg is 75250 and rounded up to the nearest 100 (but without exceeding or equaling the bigger number) forces the answer to be 75200.

How can I implement this logic without first dividing everything by 100 and using the following floating point arithmetic:

x + std::floor((y - x) * .5 * 100 + .5)*0.01

In other words, how can I do the above without floating point values but obtain the same behavior at the resolution of 100 instead of 0.01?

  • 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-06-17T12:03:18+00:00Added an answer on June 17, 2026 at 12:03 pm

    To compute the average you can do

    avg = (x + y) / 2
    

    (BTW, integer addition and division by 2 are very cheap operations even on small microcontrollers.)

    To round this to the nearest multiple of 100 (corresponding to your floating-point example) you can do

    result = ((avg + 50) / 100) * 100
    

    as integer division rounds down to the nearest integer. By changing the 50 to 0 you can always round down, while changing it to 99 always rounds up.

    Edit: Note that this method for rounding doesn’t work for negative numbers. Since integer division rounds towards zero, in that case you’ll need to subtract the 50, subtract 99 to always round down and subtract 0 to always round up.

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

Sidebar

Related Questions

Let's say I have two text files that I need to extract data out
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let say I want to create an iOS app that download music files from
Let's say we have two pages in Orchard CMS. The homepage and the About
Let's say for a moment that I have the following module in python: class
Let's say I've got two files class.php and page.php class.php <?php class IUarts {
Let's say I have two Entity classes: SocialApp and SocialAppType In SocialApp I have
Let's say you have a class library project that has any number of supplemental
Let's say I want to write a function that validates an email address with

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.