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
Round Robin Algorithm
Reil [10]

Answer:

Please check the attachment.

Explanation:

avg turnaround time = (38+7+42+33+18)/5= 27.6

avg waiting timee = (33+5+28+23+17)/5= 21.2

And its D, A C in Gantt chart at last and exit time are 33, 38 and 42 mentioned as last three in Gantt chart.

7 0
3 years ago
It is better to refuse to take a field sobriety test than to take a chance on being convicted of a DUI
Sliva [168]
I would refuse. if you dont refuse they can get probable cause
7 0
3 years ago
In the original UNIX operating system, a process executing in kernel mode may not be preempted. Explain why this makes (unmodifi
Elena L [17]

Answer:

the preemption is -> The ability of the operating

system to preempt or stop a currently

scheduled task in favour of a higher priority

task. The scheduling may be one of, but not

limited to, process or 1/0 scheduling etc.

Under Linux, user-space programs have always

been preemptible: the kernel interrupts user

space programs to switch to other threads,

using the regular clock tick. So, the kernel

doesn't wait for user-space programs to

explicitly release the processor (which is the

case in cooperative multitasking). This means

that an infinite loop in an user-space program

cannot block the system.

However, until 2.6 kernels, the kernel itself was

not preemtible: as soon as one thread has

entered the kernel, it could not be preempted to

execute an other thread. However, this absence

of preemption in the kernel caused several

oroblems with regard to latency and scalability.

So, kernel preemption has been introduced in

2.6 kernels, and one can enable or disable it

using the cONFIG_PREEMPT option. If

CONFIG PREEMPT is enabled, then kernel code

can be preempted everywhere, except when the

code has disabled local interrupts. An infinite

loop in the code can no longer block the entire

system. If CONFIG PREEMPT is disabled, then

the 2.4 behaviour is restored.

So it suitable for real time application. Only

difference is we don't see many coders using it

5 0
3 years ago
In cell D5, enter a formula to calculate the number of days for the first workshop. Add 1 to the results to include the total nu
iris [78.8K]

Answer:

D7

Explanation:

5 0
3 years ago
Greg is writing a report on becoming an advertising and promotions manager. Complete the report by correctly filling in the miss
zzz [600]

Since Greg wants to become an advertising and promotions manager, he needs to at least gain a (B) bachelor’s degree level of education, since generally, this educational background is expected from individuals who wishes to work in an entry-level position in the field of advertising.

One of the skills that he also needs to develop is (C) communication skills, because he would have to be able to communicate in both written and spoken to develop the advertisements according to the client’s desires.

8 0
3 years ago
Other questions:
  • Which statement is true? Group of answer choices Variables cannot be assigned and declared in the same statement Variable names
    5·1 answer
  • Anti-bullying laws in most states are designed to provide
    14·2 answers
  • In the INSERT statement that follows, assume that all of the table and column names are spelled correctly, that none of the colu
    9·1 answer
  • Which of the following is a full selector?
    12·1 answer
  • Write a program in python that ask the user to enter a word and then capitalizes every other letter of that word
    15·1 answer
  • Blank includes websites that encourage interaction and connection among people ,business and organizations
    13·1 answer
  • Eric would like to have a color textbook that makes it look as if the character in an image is speaking. Which object should he
    14·1 answer
  • How do you know where the home row of the keyboard is?
    14·2 answers
  • What is the output?
    7·1 answer
  • Why does rating an incorrect answer as 1 star raise its score on brainly?
    8·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!