AR14
QUESTION DESCRIPTION
Manikandan prepares for GATE Exam.
One question contains the question related to array. the question contains an array of integers, now manikandan needs to calculate sum of array elements using recursion.
Recursive function name should be as follows "int findSum(int A[], int N)"
Manikandan prepares for GATE Exam.
One question contains the question related to array. the question contains an array of integers, now manikandan needs to calculate sum of array elements using recursion.
Recursive function name should be as follows "int findSum(int A[], int N)"
TEST CASE 2
INPUT
INPUT
6
4 5 7 9 5 2
OUTPUT32
#include <stdio.h>
int findSum(int A[], int N)
{
if (N <= 0)
return 0;
return (findSum(A, N - 1) + A[N - 1]);
}
// Driver code
int main()
{ int N;
scanf("%d",&N);
int A[N],i;
for(i=0;i<N;i++)
scanf("%d",&A[i]);
printf("%d", findSum(A, N));
return 0;
}
Comments
Post a Comment