Ask Question
15 May, 10:18

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

+4
Answers (1)
  1. 15 May, 13:06
    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?
Get an answer to your question ✅ “Write a program that accepts a number as input, and prints just the decimal portion. ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers