#1 Bug in count_n ?

Lezárt
megnyitva ekkor: 2 éve hak1009 által · 1 hozzászólás
hak1009 hozzászólt 2 éve

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 hozzászólt 2 éve
Tulajdonos

I fix it THNX for you

I fix it THNX for you
alimiracle lezárta ekkor: 2 éve
Jelentkezzen be hogy csatlakozhasson a beszélgetéshez.
Nincs címke
Nincs mérföldkő
Nincs megbízott
2 Résztvevő
Töltés...
Mégse
Mentés
Még nincs tartalom.