Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVA

exponet

public class Recursion {
    public static void main(String[] args) {
        int[] arr = {23,21,321,312,31,23,12,312,312,312,3,18,200000,1};
        int arrSum = 0;
        arrSum= sigma(arr,arr.length-1);

        int sum;
        sum = sigma(arr.length);
        System.out.println("Sum of Array Elements:");
        System.out.println(arrSum+"
");
        System.out.println("sigma n ==> (Arr.length) 
"+arr.length+"
"+ sum);
    }


    public static int sigma(int n){
        if(n<=0)
            return n;

        return n + sigma(n-1);


    }

    public static int sigma(int[] arr, int l){

        if(l == 0)
            return arr[l];

        return arr[(l)] + sigma(arr,l-1) ;
    }
}
 
PREVIOUS NEXT
Tagged: #exponet
ADD COMMENT
Topic
Name
7+2 =