1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Gre4nikov [31]
3 years ago
15

How to solve a program that accepts a number as input and prints just the decimal portion

Computers and Technology
2 answers:
Mrrafil [7]3 years ago
7 0

Answer:

We can extract the decimal part of a number by casting the variable

Explanation:

Type casting is the process of  converting one datatype into another one. Basically, most of the languagues support type casting and we can use it in advantage to get the decimal part of a number.  Let assume you have a decimal number stored in your code, then let's do the following:

int integer_part = (int) float_number;

This is  a typlical way to cast a float number into a integer one. By doing so, you are getting the integer part of a float number while the decimal portion  is discarded.

Now you have a float number  and a variable with its integer part. Decimal portion is computed as follows:

float decimal_part = float_number - integer_part;

You can follow this scheme in any programming language with strong typing (datatypes  required to define a variable) and it will work ok.

lara31 [8.8K]3 years ago
3 0

<u>Answer:</u>

<em>There are 2 ways to do extract the decimal part: </em>

<u>Explanation:</u>

  • <em>First method using number </em>

<em>int main() { </em>

<em>  double doublenum = 24.535; </em>

<em>  int integerpart = (int)doublenum; </em>

<em>  double decimalpart = num - integerpart; </em>

<em>  printf(""Num = %f, integerpart = %d, decimalpart = %f\n"", doublenum, integerpart, decimalpart); </em>

<em>} </em>

  • <em>Second method using string: </em>

<em>#include <stdlib.h> </em>

<em>int main() </em>

<em>{ </em>

<em>    char* inStr = ""193.789"";          </em>

<em>    char* endptrvar;                      </em>

<em>    char* loc = strchr(inStr, '.'); </em>

<em>    long mantissaval = strtod(loc+1, endptrvar); </em>

<em>    long wholenum = strtod(inStr, endptrvar); </em>

<em>    printf(""whole: %d \n"", wholenum);      </em>

<em>    printf(""mantissa: %d"", mantissaval);   </em>

<em>} </em>

You might be interested in
What is a Slide Master?
mafiozo [28]

The correct answer is c. the default design template in a presentation program for Plato. Hope this helps :)

8 0
3 years ago
Read 2 more answers
On your Web page, you include various links and clickable images that have the ability to trigger various functions when users c
denis23 [38]

Answer:

Event is the correct answer to the given question.

Explanation:

Because when user clicks from the mouse on the image or any link then the clickable event triggered the various function. Event one of the essential part of DOM. It is an important event in the JavaScript. When the left button of the mouse is clicked on the images or links which are clickable then the mouseup event occurs.

HTML contains the set if an events when the user click on the clickable events then the JavaScript code are triggered

4 0
3 years ago
Chdtp aoxophg gr72 ae9&gt;3 zqqz
AlekseyPX
So, is this a real problem or just some random typing

8 0
4 years ago
How do you put text in MS publisher?<br><br> When do you use text wrapping?
coldgirl [10]
First question: On the Format tab, in the Arrange group, click Wrap Text. Do one of the following: Click Square to wrap text around the border of your image. Click Tight to wrap text closely around an irregularly shaped picture.


Second question: you use text wrapping when you want to surround a picture or diagram with text.

Hope this helps!
7 0
3 years ago
Como influyen las leyes en el respeto a las libertades ​
Sonja [21]

Answer:

How laws influence respect for freedoms

Explanation:

this is in English because i don't know how else to answer this

4 0
3 years ago
Other questions:
  • Which of the following accurately completes this sentence? The Internet is ____.
    6·2 answers
  • Suppose Alice, Bob, and Carol want to use secret key technology to authenticate each other. If they all used the same secret key
    10·1 answer
  • You're the network administrator for a company that has just expanded from one floor to two floors of a large building, and the
    13·1 answer
  • Which category of management information systems (MIS) combines the forecasting capability of decision support software with the
    12·1 answer
  • Student aid is based on either financial need or _____ need.
    12·2 answers
  • Which elements of a myth appear in this story from early babylon
    14·1 answer
  • What is the acronym DOS in full
    15·1 answer
  • Consider the key success factors of B2C. Is it only IT? What is most important?​
    8·1 answer
  • 9. These particular machines can be decentralized.
    9·1 answer
  • Which programming paradigm focuses on abstraction to the level of math and the elimination of side-effects and state based progr
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!