Write a C program that take a floating point number from the user and print the right most digit of number as well as print the right most digit of integral part???
If I understand, when the user types in, for example, 23.475, the program should print 5 and 3.Write a C program that take a floating point number from the user and print the right most digit of number as well as print the right most digit of integral part???
scanf("%s", num_buffer);
I wasn't sure we could assume that "input from the user" meant "character string input from a keyboard" It could have been binary data in IEEE-754 single precision which would have suggested one approach or it could have been double precision which would require an alternate approach. The OP did not specify a computing platfor or a language. I still think he needs to define his requirements.If I understand, when the user types in, for example, 23.475, the program should print 5 and 3.
I would write the program like this:
Input the number as a character string, not as a float or double, like this:
Here num_buffer would have already been declared as a character array of some suitable size.Rich (BB code):scanf("%s", num_buffer);
Now, since the array contains all the digit characters and the period for the decimal point, you can search the string for the last nonnull character in the string. That will be the rightmost digit in the fractional part of the number. You can also search the string for the character just to the left of the decimal point. That will be the units' digit.
Mark
It has everything to do with character strings.i am literally talking about floating-point number...It has nothing to do with stings...
e.g
if the user enters the number 32.415
then the output displayed on the monitor must be:
The right most digit of the number is 5
The right most digit of the integral part is 2.