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
The_provides access to the internet may also be internal​
fgiga [73]

Local Area Network (LAN), Hope this helps

4 0
3 years ago
The__ key is used to group or identify a field or record within a table. (you don't need it).
SVEN [57.7K]

Answer:

B.

Explanation:

6 0
3 years ago
Read 2 more answers
What is the most effective way to demonstrate being prepared for an interview?
Arte-miy333 [17]

To prepare for an interview, find out as much as you can beforehand. Call the person who scheduled your interview and ask:

<span>Who will you be talking to? Will you meet the manager you'd work for, or will you just talk to HR? What are the interviewer's expectations?<span>What's the dress code? Dress better than suggested. Most times, it's best to wear a professional suit. You'd be amazed how many candidates show up looking like they're going to class, not presenting a professional demeanor.</span>Get directions to the office. Plan to leave early. Keep a phone number to call if you get stuck on the bus or in traffic. If you arrive late and stressed, the interview will not go well.If you don't have a detailed job description, ask for one.</span>

That's a five-minute phone call.

3 0
3 years ago
Which of the following should be the first page of a report?
hram777 [196]

Answer:

Title page should be the first page of a report.

hope it helps!

6 0
3 years ago
This is using python.
Wittaler [7]

Answer:

discriminant = b * b - 4 * a * c

discriminant = b ** 2 - 4 * a * c

Explanation:

The operands are correct and in the right order (for python).

** is the operand for squaring something.

* is the operand for multiplying something.

- is the operand for subtracting something.

8 0
3 years ago
Read 2 more answers
Other questions:
  • i will be doing an interview to someone so plz comment down below something random and you will automatically enter
    11·1 answer
  • Before his job interview, Shabnam took the time to carefully wash and iron his best khaki pants and a button-down shirt. He even
    15·2 answers
  • What are digital forensic techniques? A. Identifying, extracting, and evaluating evidence obtained from digital media such as co
    11·1 answer
  • 2.
    8·1 answer
  • In the Microsoft Excel spreadsheet how many choices are possible when using a single IF statement​
    9·1 answer
  • 11. Its collection of toys which could be used in the game via an implanted RFID chip made Activision’s game _______ one of the
    7·2 answers
  • The data _____ component of a database management system (DBMS) is used to create and maintain the data dictionary.
    12·1 answer
  • Sampson runs his own online business, and much of his success depends on the reliability and accuracy of various online data. Ho
    11·1 answer
  • What is a program that includes a function parameter capable of doing?
    8·1 answer
  • Complete the following sentence.
    12·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!