+ 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.
8 Réponses
+ 1
It is giving an error that the floor function was not declared
+ 1
It is giving wrong output¿????
+ 1
Take a number with large number of decimals say 20
+ 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.
+ 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....
.
0
float a; int n=-1;
scanf("%f",&a);
while(a-floor(a)!=0) {
a*=10;
n++;
}
printf("%d",n);
0
use header file math.h
0
give me the testcase at which it is giving wrong answer