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
When using presentation aids A. make the aid available for the audience to look at throughout the speech. B. prepare to give you
DanielleElmas [232]

Answer: options A and B.

Option A, make the aid available for the audience to look at throughout the speech.

Option B, prepare to give your presentation without the aids, incase problem arises.

Explanation:

Presentation aids, sometimes also called sensory aids, are the resources beyond the speech itself that a speaker uses to enhance the message conveyed to the audience.

The type of presentation aids that speakers mostly make use of are visual aids; pictures, diagrams, charts and graphs, maps... Audible aids (musical excerpt, sound effects) and olfactory aids (fragrance samples or food samples) are also used.

* Presentation aids can be used throughout the speech but it should be used for essential points so as to to tire or bore the audience.

* Ensure presentation still works without the presentation aids in case of technical problems or if any problem arises at all.

* While explaining the aids, focus should be on the audience and not the presentation aids itself.

* Practice should be done with the presentation aids in advance so as to avoid any error while presenting.

Therefore, options A, B should be done when using presentation aids.

6 0
3 years ago
Analyze the following code. Which of the following statements is correct?
matrenka [14]

Answer:

that is complex wow

Explanation:

8 0
3 years ago
6.Decreasing a telescope's eyepiece focal length will:
Ghella [55]
B is the correct answer to ur questions
8 0
3 years ago
Why did it take fewer 1-inch tiles than 1-centimeter tiles to measure the length of the cookie cutter?​
Romashka-Z-Leto [24]

The inch tiles are larger, meaning they use less space.

6 0
3 years ago
How does coding work on computers?
sleet_krkn [62]
Coding works through programming/programs. Programs have different coding languages, and text files. The code within the file is known as the "source CODE" this code is used in different ways, causing for the possibility of separate binary files that computers can directly run. Hope I helped.

5 0
3 years ago
Other questions:
  • A USB zipper drive is a small data storage device that plugs into a computer's USB port.
    14·1 answer
  • What are the methods of identifying publicly switched networks?
    14·1 answer
  • The major difference between a template and another document is in _____.
    7·1 answer
  • Convert the following hexadecimal numbers to decimal numbers. (Show your work) a. 0xE3 b. 0x4A c. 0xF9
    10·1 answer
  • A user notices that a mobile device is draining power faster than is normal. What are three causes of quick battery drain? (Choo
    5·1 answer
  • The lines that connect the points of a polygon are called: (1 point)
    6·2 answers
  • Write a single statement that assigns avg_sales with the average of num_sales1, num_sales2, and num_sales3.
    15·1 answer
  • Question 1 (3 points)
    6·2 answers
  • How can the two independent clauses below be combined to form a correct complete sentence? Check all that apply.
    5·1 answer
  • Which of the following protocols is used by an email client to retrieve messages from an email server, giving users the option t
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!