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]
3 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]3 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]3 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
___________ is related to mass, but also includes the gravitational pull of the Earth.
anygoal [31]
Earth's gravity comes from all its mass. All its mass makes a combined gravitational pull on all the mass in your body. That's what gives you weight. And if you were on a planet with less mass than Earth, you would weigh less than you do here. So weight is the answer
4 0
3 years ago
Why should a person consider doing an apprenticeship?
dedylja [7]
There are many good things that can come out of it. There is good job training opportunities as well as learning the ways of the place. you can learn how people in that area work as well as their pace,emotions toward each-other and even lifestyles. there are many good outcomes to doing it.
5 0
3 years ago
URGENT!!Motors and gears play an important role in the motion of robots. Discuss the different types of motors used in robotics.
seraphim [82]

Answer:There are many types of motors are available in today's market, but mostly Tiny pager motors, servo motors, linear motors, stepper motors and DC geared motors are used in industrial robots according to their application area.  

Humanoid robots can facilitate the experimental evaluation of assistive devices by providing repeatable, measurable, human-like motion while removing the difficulties and potential safety hazards associated with human trials. To ensure that the humanoid robot is providing a valid test platform, the robot must move in a similar way as a human while wearing the assistive device. This challenge is made difficult due to the inherent variability in human motion. In this paper, we propose an approach for a quantitative comparison between human and robot motion that identifies both the difference magnitude and the difference location, and explicitly handles both spatial and temporal variability of human motion. The proposed approach is demonstrated on data from robot gait and sagittal plane lifting.  

hope it helps

5 0
4 years ago
Terry is having a problem with his computer screen. He said the screen looks distorted. When you go to check his monitor, you no
sp2606 [1]

Answer:

C. The computer's resolution has been set too low

Explanation:

When the screen of a system looks distorted and the desktop icons do not appear properly, it's a sign of low screen resolution.

This is often caused by the lack of proper display driver.

To fix this, one need to update the graphic driver. The graphic card is always available on the manufacturer's website for download download of latest drivers.

Also, screen resolution can be changed by performing the following tasks.

1. Goto Control Panel

2. Under Appearance and Personalization, click Adjust screen resolution.

3. Click the drop-down list next to Resolution,

4. Move the slider to the resolution you want

5. Click Apply.

5 0
4 years ago
Filtering is a function of _____.
Levart [38]
The answer is: switches.

Explanation:

Filtering is a function of switches.
3 0
2 years ago
Other questions:
  • • Write a program to find the maximum, minimum, and average score of players. The input to the program is a file containing play
    9·1 answer
  • Read the paragraph.
    12·2 answers
  • Which component of the Hyper-V architecture controls all communication with the physical hardware on the computer?
    8·1 answer
  • We will pass in 2 values, X and Y. You should calculate XY XY and output only the final result. You will probably know that XY X
    13·1 answer
  • An unauthorized user is a network _______ issue.
    11·1 answer
  • Josh wants to sign up for a gaming website. It will allow him to download games. He can’t find a privacy policy. Should he join
    9·2 answers
  • tls Explain in your own words how, by applying both asymmetric and symmetric encryption, your browser uses TLS to protect the pr
    8·1 answer
  • Can anyone help explain this?
    13·2 answers
  • When did Microsoft released MS-Word 2016? S When did Microsoft released MS - Word 2016​
    7·1 answer
  • What type of html list will automatically place a list marker, or bullet point, indicator in front of each item? group of answer
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!