>In an intrivew I had informed to add a array content using recurtion .
I wrote like this
void sum(int a[],int n)
{
static sum;
if (n==0)
return;
sum+=a[n-1];
sum(a,n-1);
}
i think it will work then he told to write without static variable.
then I wrote like this
int sum(int a[],int n)
{
if(n==0)
return 0;
return a[n-1]+sum(a,n-1);
}
then he told you are gone some where wrong. and told me to write whith
out using size of the array.
On that time i could not write program, but I told him that i can
limit by specifing some end character to inform the end of limit.
Now i think It would be a right program
int sum(int a[])
{
if(a[0]==-1) /* end of character I assume to be -1*/
return 0;
return a[0]+sum(++a);
}
!! Is it a right program and give me the right result !!