Ask Question
26 November, 19:47

Write a program that accepts a number as input, and prints just the decimal portion.

+1
Answers (1)
  1. 26 November, 21:30
    0
    There are 2 ways to do extract the decimal part:

    Explanation:

    First method using number

    int main () {

    double num = 23.345;

    int intpart = (int) num;

    double decpart = num - intpart;

    printf (""Num = %f, intpart = %d, decpart = %f/n"", num, intpart, decpart);

    }

    Second method using string:

    #include

    int main ()

    {

    char * inStr = ""123.4567"";

    char * endptr;

    char * loc = strchr (inStr, '.');

    long mantissa = strtod (loc+1, endptr);

    long whole = strtod (inStr, endptr);

    printf (""whole: %d / n"", whole);

    printf (""mantissa: %d"", mantissa);

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a program that accepts a number as input, and prints just the decimal portion. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers