Answer to Question #251856 in C++ for Sarang

Question #251856

Can you share a concept of a function?

  • It can be a simple C++ code applying a user-defined function OR
  • An animated image / video doing activities; explain how this can be related to our function discussion.
1
Expert's answer
2021-10-16T01:44:06-0400


#include <iostream>


using namespace std;
int getSum(int arr[],int n){
    int sum=0;
    for(int i=0;i<n;i++){
        sum+=arr[i];
    }
    return sum;
}
int main()
{
    int n1=9;
    int n2=9;
    int array1[n1]={1,2,3,4,5,6,7,8,9};
    int array2[n2]={10,20,30,40,50,60,70,80,90};
    
    cout<<"\nThe sum of the elements in the first array is: "<<getSum(array1,n1);
    cout<<"\nThe sum of the elements in the second array is: "<<getSum(array2,n2);
    return 0;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS