I have this code, I want the "sum" function (which I want to add the first and last position of the array) to be applied to a given array. How do I take the last position of the array?
#include <stdio.h>
#define CUBO(a) a*a*a
int suma (int a[]);
int main()
{
int size;
printf("cant ar: ");
scanf("%i",&size);
int ar[size];
for (int i=0; i<size; i++)
{
printf("valror %i: ",i+1);
scanf("%i",&ar[i]);
}
printf("la suma es %i",suma(ar[]));
return 0;
}
int suma(a[]){
int sum;
sum= a[0] + CUBO(a[size-2]);
return sum;
}
The compiler tells me that "size" is not declared in the function, in python it would be a[-1], but how do I do it in C so that it indicates the last position of the array?