+ 2

How to count the number of digits after a decimal point?

I was programming in C and then I came across this question.. The problem is that this problem seems unsolvable.

26th Nov 2016, 2:22 AM
Aadarsh Singh
Aadarsh Singh - avatar
8 Réponses
+ 1
It is giving an error that the floor function was not declared
26th Nov 2016, 3:05 AM
Aadarsh Singh
Aadarsh Singh - avatar
+ 1
It is giving wrong output¿????
26th Nov 2016, 3:08 AM
Aadarsh Singh
Aadarsh Singh - avatar
+ 1
Take a number with large number of decimals say 20
26th Nov 2016, 3:11 AM
Aadarsh Singh
Aadarsh Singh - avatar
+ 1
float can't even handle 20 numbers after decimal point. So if you want to make the program handle large number of decimals than use string for input and simply count all the characters after '.' char a[50]; int i=0, L; scanf("%s",a); L= strlen(a); while(a[i]!='.') { i++; } printf("%d",L-i-1); use string.h for strlen and you can increase the size of string according to constraints.
26th Nov 2016, 3:31 AM
Aditya Aggarwal
Aditya Aggarwal - avatar
+ 1
Sir for a beginner like me are you not going on typing some advanced programs???? Can't you do anything with for, if else, while etc.... .
26th Nov 2016, 3:51 AM
Aadarsh Singh
Aadarsh Singh - avatar
0
float a; int n=-1; scanf("%f",&a); while(a-floor(a)!=0) { a*=10; n++; } printf("%d",n);
26th Nov 2016, 3:02 AM
Aditya Aggarwal
Aditya Aggarwal - avatar
0
use header file math.h
26th Nov 2016, 3:06 AM
Aditya Aggarwal
Aditya Aggarwal - avatar
0
give me the testcase at which it is giving wrong answer
26th Nov 2016, 3:11 AM
Aditya Aggarwal
Aditya Aggarwal - avatar