- 1

In C, how do you extract and print the rightmost number of the integral portion of a float?

I couldn't figure out the code required to make this work. https://code.sololearn.com/cvCKScPz1owh/?ref=app

29th Jan 2020, 9:13 AM
Steven Iannucci
Steven Iannucci - avatar
4 odpowiedzi
0
#include <stdio.h> int main(void) { /* variable declaration */ char name[20]; float num; int x; /* statements */ printf("What is your name? "); scanf("%s", name); printf("Hi %s - this program extracts and prints the rightmost digit of the integral portion of a float\n", name); printf("Enter a number: "); scanf("%f", &num); x = (int)num; printf("The rightmost digit is %d\n", x % 10); return 0; }
29th Jan 2020, 9:50 AM
Steven Iannucci
Steven Iannucci - avatar
0
Can explain more with an example, to understand what you expecting exactly..? If you mean x= 1.2345 to 1, then printf("%d", (int) x); Output: 1
29th Jan 2020, 9:22 AM
Jayakrishna 🇮🇳
0
That's OK. But let me know that from Ex 4.57 integral portion is 4 Decimal part is 57 Which one you need to extract? Specify with example..
29th Jan 2020, 9:40 AM
Jayakrishna 🇮🇳
0
That's fine.. You are getting the output.. Is there any need changes?
29th Jan 2020, 9:56 AM
Jayakrishna 🇮🇳