-4

i'am triyng to solve this simple exercise for my code class but i tried everthing and have no ideia why this code inst working

// Develop a modular structure with a function that you receive through
// parameter a positive integer and returns the number quantity of this number.

#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#include <string.h>
#include <math.h>

int digitos(float N){
    int i;
    for(i = 0;i<10;i++){
        printf("%f\n",N/pow(10,i));
        if((N/pow(10,i))<0.0){
            return i;
        }
    }
}


int main(){
int d ;
    d = digitos(3000);
    printf("The number of digist %d",d);

}
Mat
  • 202,337
  • 40
  • 393
  • 406
  • Does this answer your question? [Is floating point math broken?](https://stackoverflow.com/questions/588004/is-floating-point-math-broken) – πάντα ῥεῖ Mar 28 '21 at 19:26
  • it's always better if you explain what you are trying to achieve with the code and what's not working, instead of waiting for us to look at the code and try to figure it ourselves ;) – Muratcan Akcay Mar 28 '21 at 19:43

1 Answers1

3

Looks like an issue with your math. You're never going to get a negative number unless N itself is negative. Did you mean:

if ((N/pow(10, i)) < 1.0) {
user3832673
  • 369
  • 2
  • 7