Advertisement
AntonioVillanueva

Calculo factorial RUST

Jan 8th, 2025
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.21 KB | None | 0 0
  1. fn factorial (n: u32) -> u32 {
  2.  
  3.     if n==0{
  4.         return 1;
  5.     }
  6.    
  7.     let mut product =1;
  8.    
  9.     for i in 1..=n{
  10.         product *=dbg! (i);
  11.     }
  12.    
  13.      product
  14. }
  15.  
  16. fn main(){
  17.     let n=-1;
  18.     println! ("{n}! ={}",factorial(n));
  19. }
  20.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement