Solution for Exercise 7-15
ex0715
#include <stdio.h> int main() { float fav; printf("What is your favorite number: "); scanf("%f",&fav); printf("%f is my favorite number, too!\n",fav); return(0); }
Notes
* Only three changes are required to convert fav
into a float variable: The declaration on Line 5 and the %f
for scanf() in Line 8 and printf() in Line 9.
* If you type a whole number, the scanf() function reads it as a floating point value. That's okay for program input, but remember that when you write your code you should specify the decimal when typing a float value.
Copyright © 1997-2024 by QPBC.
All rights reserved