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
krok68 [10]
2 years ago
6

Write a program that accepts a number as input, and prints just the decimal portion.

Computers and Technology
2 answers:
Olegator [25]2 years ago
8 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 num = 23.345; </em>

<em>  int intpart = (int)num; </em>

<em>  double decpart = num - intpart; </em>

<em>  printf(""Num = %f, intpart = %d, decpart = %f\n"", num, intpart, decpart); </em>

<em>} </em>

  • <em>Second method using string: </em>

<em>#include <stdlib.h> </em>

<em>int main() </em>

<em>{ </em>

<em>    char* inStr = ""123.4567"";          </em>

<em>    char* endptr;                       </em>

<em>    char* loc = strchr(inStr, '.'); </em>

<em>    long mantissa = strtod(loc+1, endptr); </em>

<em>    long whole = strtod(inStr, endptr);  </em>

<em>    printf(""whole: %d \n"", whole);      </em>

<em>    printf(""mantissa: %d"", mantissa);   </em>

<em>} </em>

kirill [66]2 years ago
5 0

Answer:

The program to this question can be given as:

Program:

#include <iostream> //header file

using namespace std;

void cal(double number) //defining method cal

{

double decimal_part; //defining variable

int integer_part; //defining variable

integer_part = (int)number; //type casting

decimal_part = number - integer_part;  //holding decimal value

cout<<"number you inserted :"<<number<<endl;  //print value

cout<<"integer part :"<<integer_part<<endl;  //print integer part

cout<<"decimal part :"<<decimal_part<<endl; // print decimal part

}

int main()  //defining main method

{

double number; //defining variable number

cout<<"Input floating point number :"; //message

cin>>number; //taking input from user

cal(number); //calling function and passing value in function

return 0;  

}

Output:

Input floating point number :786.786

number you inserted :786.786

integer part :786

decimal part :0.786

Explanation:

  • In the above C++ language program, firstly include a header file then define a method that is "cal". This method accepts a double parameter and returns nothing because its return type is void.
  • Inside a method, two variable is defined that is "integer_part and decimal_part". In which variable integer_part is an integer variable that holds only integer value and variable decimal_part is used to holds decimal value only and to print function calculated value the cout (print function).
  • In the main method, a variable number defines that datatype is a double type that accepts a decimal or floating-point value from user input and passes the value in the function parameter and call the function.
You might be interested in
Play among us with me
omeli [17]

Answer:

cool

Explanation:oof

8 0
2 years ago
Read 2 more answers
Assuming dataFile is an ofstream object associated with a disk file named payroll.dat, which of the following statements would w
svet-max [94.6K]

Answer:

dataFile << salary;

Explanation:

To write salary to a file (payroll.dat) using ofstream, you make use of the following instruction:

<em>ofstream dataFile; </em>

<em>myfile.open ("payroll.dat"); </em>

<em>myfile <<salary; </em>

<em>myfile.close();</em>

<em />

This line creates an instance of ofstream

<em>ofstream dataFile; </em>

This line opens the file payroll.dat

<em>myfile.open ("payroll.dat"); </em>

This is where the exact instruction in the question is done. This writes the value of salary to payroll.dat

<em>myfile <<salary; </em>

This closes the opened file

<em>myfile.close();</em>

<em />

<em />

8 0
2 years ago
How can i save a word 2016 document as a word 2016 document?
Lana71 [14]
Type 2016 document.pdf.files
3 0
3 years ago
5. How is shutter speed generally measured? What do the measurements mean?
Leokris [45]
Shutter speed<span> is </span>generally measured<span> by the scientific symbol “s”. The </span>measurement means<span> that the </span>measurements<span> in "s" is the reciprocal of the number when the denominator is put on the numerator side instead. ... Aperture is </span>measured<span> by f's.</span>
6 0
3 years ago
Read 2 more answers
Describe your dreams include lifestyle,job,house,friends
n200080 [17]
So, this is an answer of your choice. What it is trying to ask is tell us what your dream home, job, husband, and so on. For example: My dream home is a mansion in Mississippi by the beach. My dream job is a doctor. Those are prime examples of a dream home and job. Now your answer shouldn't be the same as mine. Your's should be something different. Unless, you want a mansion in Mississippi by the beach and you would like to be a doctor. In other words it is asking you to tell us what you want you home, lifestyle, job, friends, and possibly your DREAM pet. Hope this helps.

3 0
2 years ago
Read 2 more answers
Other questions:
  • When sending an electronic cover letter, an e-mail address is sufficient contact information.
    10·2 answers
  • What would be the best engine to use for making a 3d beginner game
    9·1 answer
  • When activated, an Excel object has all the features of an Excel ______?
    9·2 answers
  • What is the output of the following C++ code?
    14·1 answer
  • Which factor is NOT used to determine who can be let go during a downsizing?
    8·2 answers
  • How would you describe binary to someone ??<br> PLEASE ANSWER I WILL GIVE U BRAINLY!!
    15·2 answers
  • Please answer this question​
    8·1 answer
  • During the data transmission there are chances that the data bits in the frame might get corrupted. This will require the sender
    8·1 answer
  • Four examples of computer virus​
    10·1 answer
  • (b) Cell B12 contains the formula, ROUND((SUM(B5:B9)*D1),1).
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!