/* * Chapter5 * Selfttest2 * Problem 3 * Purpose: Write a program which outputs the following result * when the user inputs a float. * * The 3.14 in italic means the user input value. * Enter a float number: 3.14 * The number 3.14 consists of 3 and 14 * The sum of two pars is 17 * * Use scanf function to obtail the needed pieces (3 dot 17). * Make the program work without using %f specifier. */ #include // include functions from stdio.h when compiling int main(void) // header for function main, // takes nothing, returns int { int num1, num2; printf("Enter a floating point number: "); //prompt for user input scanf("%d.%d", &num1, &num2); // Scan for first digit and a period //scanf("%d", &num2); // scan for second number getchar(); // clear the input buffer of the newline printf("The number %d.%d", num1,num2); printf("consists of %d and %d\n", num1,num2); printf("The sum of two pars is %d\n", num1+num2); return 0; }