Ask Question

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

+3
Answers (1)
  1. 27 May, 11:28
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers