How do I print out only the decimal places for a number in C?

Discussion in 'Programming' started by benpolska, Jan 24, 2011.

  1. #1
    So here is the question:

    Create a program that will read in a floating point number and output the decimal part of the number. e.g. given 3.14159, it will output .14159

    I do not know the %f for only showing the decimal part of the number the user enters. What is it to only show the decimal places of a number?

    Please explain your answer.

    int main()
    {
    float n1;

    printf("Please enter a number with 4 decimal places:\n");
    scanf("%f", &n1);
    printf("The decimal places you entered are %f .\n", n1);
     
    benpolska, Jan 24, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Maybe they want you to read a string and split it at the decimal.
     
    Cash Nebula, Jan 29, 2011 IP