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
In a "block" containment strategy, in which the attacker's path into the environment is disrupted, you should use the most preci
Slav-nsk [51]
The containment strategy prevents intruders from removing information assets from the network, and prevents attackers from using the organization's network as a launch point for subsequent attacks.
In a "block" containment strategy, in which the attacker's path into the environment is disrupted, you should use the most precise strategy possible, starting with <span>blocking a specific IP address. Correct answer: C

</span>

8 0
3 years ago
What is a way to minimize technical problems with your computer
Gala2k [10]
Buy or get new software that protects ur pc, such as a "fixmestix" or just download new software or use a disc 
4 0
3 years ago
ISDN stands for Internet Services Dynamic Network True/False
aev [14]

The answer is the second option "false." ISDN does not stand for Internet Services Dynamic Network it stands for Integrated Services Digital Network. ISDN is the international communication center for sending data, video, and voice over telephone wires.

Hope this helps.

7 0
3 years ago
Write an algorithm to create a customer’s bill for a company. The company sells only five different products. TV, VCR, Remote Co
alukav5142 [94]

Answer:

so

tv= 400$

VCR= $220

remote controller= $35

CD Player= $280

Tap recorder= $90

so total = $1025 total

here 8% sale tax increase so is 82$ so

1025-82$ = 943 total amount

increase or decrease tax according to your question :)

6 0
3 years ago
Ava calls tech support because she is unable to send information that a customer has requested. The tech support person tells he
Blizzard [7]

Answer:

Outlook as it is a common email aplication which may experience some issues

Explanation:

7 0
3 years ago
Other questions:
  • There is a colony of 8 cells arranged in a straight line where each day every cell competes with its adjacent cells(neighbour).
    11·1 answer
  • In which area of engineering does material selection play a vital role a design optimization b forensic engineering c mechanical
    6·1 answer
  • There are two types of short-term memory: one type is involved in the input and storage of new information, the other type of sh
    9·1 answer
  • When planning your educational and career path, it makes sense to consider where you want to work and what type of work you want
    14·1 answer
  • A 10 Superscript negative 910−9​-F capacitor ​(11 nanofaradnanofarad​) is charged to 5050 V and then disconnected. One can model
    5·1 answer
  • Which command will display each line in the text file based on the alphabet?
    10·1 answer
  • when files on storage are scattered throughout different disks or different parts of a disk, what is it called
    10·1 answer
  • Add my sna-p dkarpik58?...
    9·1 answer
  • Charles was supposed to present his PowerPoint slides to his classmates in a classroom, but now he has to present in the auditor
    12·2 answers
  • A _______ is a group of elements that you want to style in a particular way.
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!