AleksandarArkan

R-Somma tutti gli elementi di un vettore

Mar 26th, 2015
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. int sum(int arr[],int size){
  2.     //caso base
  3.     if(size==0)
  4.         return 0;
  5.     else
  6.     //passo ricorsivo, somma l'elemento e rifai la stessa cosa per il successivo
  7.     //il passo ricorsivo considera come elemento attuale quello in posizione -1, quindi alla
  8.     //fine verra' sommato anche l'elemento in posizione 0.
  9.  
  10.         return sum(arr,size-1) + arr[size-1];
  11. }
Advertisement
Add Comment
Please, Sign In to add comment