#1 Bug in count_n ?

Gesloten
2 jaren geleden werd geopend door hak1009 · 1 opmerkingen

If one calls count_n(0) wouldn't the result be 0? Shouldn't there be a check at the beginning of the function like

pub fn count_n(mut n: i32) -> i32 {
// count the digits in the number
  if n == 0 {
    return 1;
  }
  let mut count = 0;
  if n <0 {
    n=n*-1
  }
  while n>0 {
    n=n/10;
    count = count +1;
  }
  count
}
If one calls count_n(0) wouldn't the result be 0? Shouldn't there be a check at the beginning of the function like ```rust pub fn count_n(mut n: i32) -> i32 { // count the digits in the number if n == 0 { return 1; } let mut count = 0; if n <0 { n=n*-1 } while n>0 { n=n/10; count = count +1; } count } ```
alimiracle reageerde 2 jaren geleden
Eigenaar

I fix it THNX for you

I fix it THNX for you
Sign in to join this conversation.
Geen label
Geen mijlpaal
Geen verantwoordelijke
2 deelnemers
Laden...
Annuleren
Opslaan
Er is nog geen inhoud.