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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T19:05:07+00:00 2026-05-30T19:05:07+00:00

Possible Duplicate: C programming division probably my question is very simple and stupid. I

  • 0

Possible Duplicate:
C programming division

probably my question is very simple and stupid.
I would like to store the value of a division, in particular 1 / x where x is a
integer value.

int x = 17;
double result = 1/x;

I try to do it but I always get 0.000000 ... I try to enter a value fixed in x, for example 1/17 but always get the same value .. what’s Wrong?

  • 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-30T19:05:08+00:00Added an answer on May 30, 2026 at 7:05 pm

    You are doing integer division.

    Try the following and it will work as expected:

    int x = 17;
    double result = 1.0 / x;
    

    The type of the 1 in the expression you have above is int, and the type of x is int. When you do int / int, you get an int back. You need at least one of the types involved to be floating point (float or double) in order for floating point division to occur.

    Unlike in Mathematics, division in C++ can either refer to truncated integer division (what you did) or floating point division (what I did in my example). Be careful of this!

    In my example, explicitly what we have is double / int -> double.

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

Sidebar

Related Questions

Possible Duplicate: What is a monad? How would you describe a monad in non-programming
Possible Duplicate: C programming division I'm trying to calculate the period of accelerometer updates
Possible Duplicate: C# driver development? I would like to know if I can do
Possible Duplicate: Counting inversions in an array This is a programming question that I
Possible Duplicate: C Programming: Forward variable argument list. What I'd like to do is
Possible Duplicate: Similarity Between Colors I know it's not a programming question but I
Possible Duplicate: What exactly is RESTful programming? What are RESTful web services? What would
Possible Duplicate: What is your longest-held programming assumption that turned out to be incorrect?
Possible Duplicate: How costly is .NET reflection? I am currently in a programming mentality
Possible Duplicate: Haskell vs. procedural programming in the real world Few times I heard

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.