C - Write program to read float value from user

Requirements

Write program to read float value from user

Hint

To read a floating-point value, specify a float variable and use the appropriate conversion character; %f.

Demo

#include <stdio.h>

int main()//w  ww .  ja va 2 s.co  m
{
    float fav;

    printf("What is your favorite number: ");
    scanf("%f",&fav);
    printf("%f is my favorite number, too!\n",fav);
    return(0);
}

Result

The scanf() function stops reading text input at the first white space character, space, tab, or Enter key.

Related Exercise