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 tips or techniques should you keep in mind when shooting photographs on a rainy day?
SashulF [63]
Simple: Keep your camera protected from the rain

Here are some tips for photographing during rainy day: 1) Use image stabilization or tripod.
2) Choose a larger aperture.
3) Change the object on which you focus.
4) Have a well-defined center of interest.
5) Review all images.
6) Use exposure compensation.

7 0
2 years ago
Write a program named split_me.py that accepts a string in the format Age.FirstName and returns the value FirstName is Age years
zmey [24]

age,name = input('Enter a string: ').split('.')

print(name+' is '+age+' years old. Length of '+name+' is '+str(len(name)))

I wrote my code in python 3.8. I hope this helps.

5 0
3 years ago
What command line utility can be used to repair the bcd on a windows installation?
Afina-wow [57]
You can use the following command Bootrec /rebuildbcd
8 0
3 years ago
What is the full form of GUI​
Nonamiya [84]

Answer:

The graphical user interface (GUI /dʒiːjuːˈaɪ/ jee-you-eye or /ˈɡuːi/) is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, instead of text-based user interfaces, typed command labels or text navigation.

4 0
3 years ago
Read 2 more answers
Critical Thinking Questions
Hoochie [10]

Answer:

One example of syntax in Logo is “[”. Two examples of Java are “;” and “{“or “}”. If you don’t use these parts of syntax then you could get a Syntax error, this will make you have to stop the code and debug.

Explanation:

6 0
2 years ago
Read 2 more answers
Other questions:
  • Given that the time to read data off a 7200 rpm disk drive will be roughly 75% of a 5400 rpm disk, at what idle time of the 7200
    13·1 answer
  • As the performance of PCs steadily improves, computers that in the past were classified as midrange computers are now marketed a
    9·1 answer
  • If you have a long title for a table and need it to span several cells, you can use A. Merge Cells. B. Split Cells. C. Insert Co
    5·1 answer
  • So can u please follow my new ig acc i just started it yesterday its called stunnerspamz
    5·2 answers
  • Ile 1 cm<br> ?<br> 50 m<br> The an
    5·2 answers
  • Be able to list a technology-based company and discuss whether it enjoys sustainable competitive advantage based on the resource
    13·1 answer
  • A web application is an example of:
    7·1 answer
  • Can somebody help me out
    15·1 answer
  • What should a pie chart represent?
    6·1 answer
  • When you use the predict step in the IPDE process you
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!