#1 Bug in count_n ?

Closed
opened 1 year ago by hak1009 · 1 comments
hak1009 commented 1 year ago

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 commented 1 year ago
Owner

I fix it THNX for you

I fix it THNX for you
Sign in to join this conversation.
No Label
No Milestone
No assignee
2 Participants
Loading...
Cancel
Save
There is no content yet.