0

C language

How can i pass only element to function Example.. I want that if i input sum(arr[0],arr[1],arr[2]) Than it show sum of 0,1,2 element But if i take input 0,1,2,3,4 than it show sum of it Here is my try but i didn't get it (This is just example it didn't work ) (It is for showing that i try to do it but it didn't work) Int main() { Int Arr[5] = {1,1,2,3}; Printf("%d",sum(arr[2],arr[1])); } Sum(int arr[0],int arr[1]) { Int sum =0; For(int i=0;i<2;i++) Sum=sum+arr[i]; Return 0; }

17th Dec 2021, 8:41 AM
Vishu
1 Answer
+ 2
Just send the entire array to the function. ( Make sure to keep track of its size though )
17th Dec 2021, 9:04 AM
Arsenic
Arsenic - avatar