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]
2 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]2 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]2 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
How many different keys can be used in a single sort?   A. 1   B. 2   C. 3   D. 4
PolarNik [594]
I would belive it be 
C.3
3 0
2 years ago
Read 2 more answers
Which sentence best describes a story's rising action?
MAXImum [283]

Answer:

So first off I’m pretty sure you meant ELA class, but I will still answer the question for you. The sentence that best describes a stories rising action is when it describes the conflicts that lead to the climax of the story. The climax is the main point in a story, and usually towards the middle. (Even though this can vary in book series)

Explanation:

Rising action takes place in a book right before the climax, the main point. This really matter because they have to work it up to the climax. Think of it like a graph. The line won’t just shoot up, it will gradually go up, then gradually go down.

Hope this helped!!

6 0
2 years ago
What are the effects deforestation have on a river system?
Nikolay [14]
Deforestation affects rivers in these ways
1.There is a loss of habitat for wild animals
2. Destruction of land due to floods, mudslides, 
3. Water cycle and Animal Cycle are disturbed
( ex. transpiration rate; beavers building dams)
4. Greater amount of Green House gases


8 0
3 years ago
Which device assists with medical imaging
masya89 [10]
MRI- Magnetic Resonance Imaging

        OR

USI- Ultrasound Imaging
5 0
3 years ago
Read 2 more answers
11. First featured in Donkey Kong, the jump button let to the creation of a new game category known as __________
Vinil7 [7]

Answer:

C

Explanation:

7 0
2 years ago
Other questions:
  • Which of the file names below follows standard file naming convention
    13·1 answer
  • Critics are concerned about how easy it is to upload and download music on the Internet because:
    10·2 answers
  • An enterprise DBMS is automatically capable of serving as a mobile DBMS. There are no special issues raised by mobility. True Fa
    11·1 answer
  • Tim has an old server computer that his company uses as a backup. One of the hard drives has gone bad and needs to be replaced.
    14·1 answer
  • The collection of all component frequencies iscalled _____________
    14·1 answer
  • 1) Why is angle of view important? What are some of the ways that you can do this?
    6·1 answer
  • Android OS "AFTER" Alpha.<br><br> A. Bubblegum<br><br> B. Beta<br><br> C. Berry<br><br> D. Buzz Cola
    10·1 answer
  • Describe one practical application of total internal reflection. ​
    14·1 answer
  • The _________ operator returns the distance in bytes, of a label from the beginning of its enclosing segment, added to the segme
    9·1 answer
  • Three types of query​
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!