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
Leslie’s parents put a big dry-erase board on the refrigerator and let the kids write suggestions for how to organize and assign
blondinia [14]

Answer

determine possible solutions

Explanation:

im assuming

ty for the thanks

5 0
2 years ago
Samantha has to create a video for her science project on the blossoming of a flower from a bud to one with fully opened petals.
Hitman42 [59]
Samantha would have to use the ‘time-lapse’ technique to film the video in the most efficient way.
5 0
3 years ago
Read 2 more answers
History timeline: who developed what elements first Windows OS and Apple OS?
Harrizon [31]

Answer:

i think bill gates

Explanation:

5 0
3 years ago
Read 2 more answers
What is the name of the nearest major galaxy to Milky-Way ?
nika2105 [10]
The Andromeda Galaxy would be my answer.
3 0
3 years ago
Why is audio greyed out on powerpoint ms office 2011?
-BARSIC- [3]
Because its a old type of software and probably wont run on your computer
7 0
3 years ago
Other questions:
  • 10. Which of these is not an HTTP verb? PUT AJAX GET DELETE
    12·1 answer
  • What is the purpose of a turbine in a power plant?
    14·1 answer
  • Seth is considering advertising his business using paid search results.What do you think makes paid search advertising so effect
    11·2 answers
  • Which ORDER BY clause causes 10 rows to be retrieved from the result set, starting with the 20th row?
    5·1 answer
  • A ________ is a single media file including art, sound, animation, or movies.
    9·1 answer
  • 8.7 lesson practice question 1
    13·1 answer
  • If you wanted to divide an integer variable by 2, which of the following lines of code would you use? total = int + 2 total = in
    6·1 answer
  • Because travel distance, cost of living, and other factors vary among the three regions, the annual cost of having a salesperson
    14·1 answer
  • A Network Intrusion Detection System watches for potentially malicious traffic and _______ when it detects an attack.
    15·1 answer
  • Question 4 of 25
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!