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
NEED HELP FAST
olganol [36]
The answer is b absloute is very incorrect because the ressinanse is a very important period


3 0
2 years ago
Read 2 more answers
What is computer topology​
Nitella [24]

Answer:

In networking, topology refers to the layout of a computer network. ... Physical topology means the placement of the elements of the network, including the location of the devices or the layout of the cables. Logical topology maps the flow of data, regardless of the physical layout.

...hope it helps...

7 0
3 years ago
Read 2 more answers
Write a script named numberlines.py. This script creates a program listing from a source program. This script should: Prompt the
ddd [48]

Answer:

See explaination for program code.

Explanation:

inputFileName = input("Input filename: ") outputFileName = input("Output filename: ") inputFile = open(inputFileName, "r") outputFile = open(outputFileName, "w") count = 1 for line in inputFile: newLine = str(count).rjust(4, " ") + "> " + line outputFile.write(newLine) print(newLine) count += 1

4 0
2 years ago
How can I hide my cracked phone screen? or How can I fix it myself without my parent finding out? or How can I fix my phone with
sammy [17]
Ummm I don’t know how to answer that
8 0
2 years ago
Write the definition of a function half which recieves a variable containing an integer as a parameter, and returns another vari
Alchen [17]

Answer:

int half(int x){

int a=x/2;

return a;

}

Explanation:

function <em>half(x)</em> which has return type <em>integer</em> and accept an <em>integer </em>type parameter <em>'x'</em> and return the an <em>integer </em>value in variable <em>'a' </em>which is closest to <em>half</em>  that of the parameter '<em>x'</em>.

5 0
3 years ago
Other questions:
  • What do you have to do to see the html code on a website?
    15·2 answers
  • A ____ is text and graphics that print at the bottom of every page.
    12·1 answer
  • Renee is creating a multimedia presentation for a website that requires user interaction. Which multimedia type is Renee using?
    5·2 answers
  • "Once a business operations analysis is completed and change needs to
    7·2 answers
  • Write a C program to calculate salary raise for employees. If salary is between$ 0 &lt; $ 30000 the rate is 7.0%If salary is bet
    8·1 answer
  • I need some help with this assignment. I'm having difficulty trying come up ideas to use here. Can I get any help?
    5·1 answer
  • second question today 25 POINTS: What is the formula to balance a lever when both effort and resistance are present?
    14·1 answer
  • You are developing a Website that is going to be viewed extensively on smartphones and tablets. Which of the following should yo
    7·1 answer
  • Place the steps for attaching a file to a message in order from top to bottom.
    12·1 answer
  • Your friend says, “I can’t ever watch a streaming movie without it pausing for long moments. It makes me crazy!” What might you
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!