Question

Consider the following problem: given number of type double, we would like to extract the integer...

Consider the following problem: given number of type double, we would like to extract the integer part and the fractional part. For example if double 1.25 is given, the integer part is 1 and the fractional party is 0.25. Propose a function prototype that takes a double number and produces the integer part and the fractional part and then write the code for the function.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
#include <stdio.h>

// prototype
void fraction_part(double, int *, float *);

int main() {
    float num = 5.76, fraction;
    int integer;
    fraction_part(num, &integer, &fraction);
    printf("Integer part = %d\n", integer);
    printf("Fraction part = %f\n", fraction);
    return 0;
}

void fraction_part(double num, int *integer, float *fraction) {
    *integer = (int) num;
    *fraction = (float) (num - *integer);
}
Add a comment
Know the answer?
Add Answer to:
Consider the following problem: given number of type double, we would like to extract the integer...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Problem 1) (15 points) File Search You are given a file of integers named MyData.dat. We...

    Problem 1) (15 points) File Search You are given a file of integers named MyData.dat. We would like to find the number of integers that are greater than or equal to a given value. Write a C program that searches the file for integers that are greater than or equal to the integer entered by the user. Your main function should call a C function that receives as input a file pointer and a target integer, and returns the number...

  • problem 1 midterm-1-coding.pdf C:/Users/Cute%20khalsa/Downloads/midterm-1-coding.pdf 2 Problem #1 The first problem is to write the from.fixed point...

    problem 1 midterm-1-coding.pdf C:/Users/Cute%20khalsa/Downloads/midterm-1-coding.pdf 2 Problem #1 The first problem is to write the from.fixed point function, using "bit fiddling". double from_fixed point(unsigned short x); The parameter x is a representation (sometimes called a packed representation) of a fixed- point number. The right most 4 bits of x are the fractional part of the number. We will call them b. The leftmost 12 (or more) bits of x are the integer part of the number. We will call them a...

  • In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand....

    In C++ Do not use a compiler like CodeBlocks or online. Trace the code by hand. Do not write "#include" and do not write whole "main()" function. Write only the minimal necessary code to accomplish the required task.                                                                                                           Save your answer file with the name: "FinalA.txt" 1) (2 pts) Given this loop                                                                                              int cnt = 1;     do {     cnt += 3;     } while (cnt < 25);     cout << cnt; It runs ________ times    ...

  • Consider the following C struct that represents a complex number. struct complex {    double real;    double...

    Consider the following C struct that represents a complex number. struct complex {    double real;    double imaginary; }; (a) [20 points/5 points each] Change this struct into a class. Make the member variables private, and add the following to the class: A default constructor that initializes the real and imaginary parts to 0. A constructor that allows initialization of both real and imaginary parts to any double value. A public member function that returns the magnitude of the complex number....

  • Write C++ code that creates an integer variable called number. Dereference a given pointer gPointer and...

    Write C++ code that creates an integer variable called number. Dereference a given pointer gPointer and places that value into the variable number. The pointer gPointer will have been declared and set to point to a value before your code runs. Your code will be placed inside the main function with all the appropriate #includes. After your code runs, the test case will execute the following code: cout << "number = " << number << endl; For example: Test Result...

  • For programming C language This problem will be briefly discussed in Lab2 and the TĀ will...

    For programming C language This problem will be briefly discussed in Lab2 and the TĀ will give you hints to solve it. However, the TĀ will not write the code. This code is a bit complicated, so try to understand the process from the TA so that you can continue working on it at home. Reverse the Number Write a program that takes a 5-digit number as input and print the reverse of the number. Sample Input/Output: Enter a five...

  • Given that a method receives three parameters a, b, c, of type double, write some code,...

    Given that a method receives three parameters a, b, c, of type double, write some code, to be included as part of the method, that checks to see if the value of a is 0; if it is, the code prints the message "no solution for a=0" and returns from the method. Our original information was that the probability of High demand was .6. We collected the following new information about what happened to demand when there was an improving...

  • fo d and ael Te of she ct Pr of te eWea wd t led ad...

    fo d and ael Te of she ct Pr of te eWea wd t led ad The St ad.a wch i the a o a eped a p a d w bee sal ta oth of ype d The ct cag te e o od sal ta 1. (20 points) Write complete code for each of the following functions No function needs more than 8 instructions excluding the eurly braces. Please do not write excessively long code for any of...

  • 20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real l...

    20. [5 points] Rewrite the following ML. function using patterns fun factn. ifn-0 then 1 else n fact (n-1) 21. [S points) Using map function, write an ML function int2real of type int list real list that takes a list of integers and returns the same numbers converted to real. For example, if the input is [1,2,3], the output should be like [1.0,2.0,3.0 22. [5 points] Using foldr function, write a function duplist of type·a list 'a list that takes...

  • In python.. If we want the computer to pick a random number in a given range...

    In python.. If we want the computer to pick a random number in a given range say to write code for Picking a random element from a list or pick a random card from a deck, flip a coin etc. we can use Random module The Random module contains some very useful functions one of them is randrange() randrange(start, stop) Example from random import randrange for i in range (3): print ("printing a random number using randrange(1, 7)",r andrange(1, 7))...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT