Answer to Question #218403 in C++ for Fuad Endris

Question #218403
1.Write C++ program to accept N number from the user and print the elements of the array in reverse order using a pointer.
2.Write C++ program that accepts N elements from the user and display the sum of array elements using pointers.
1
Expert's answer
2021-07-18T01:24:06-0400

1..


#include <iostream>


using namespace std;
void reverse(int * arr,int N){
    int arr2[N];
    
    for(int i = 0; i < N; i++){
        arr2[i] = arr[N-i-1];
    }    
    cout << "Reversed Array\n";
    for(int i = 0; i < N; i++){
        cout << arr2[i] << " ";
    }
}
int main()
{
    
    int N=5;
    int arr[N];
    cout<<"Enter "<<N<<" numbers:\n";
    for (int i=0;i<N;i++){
        cin>>arr[i];
    }
    reverse(arr,N);
    return 0;
}


2..

#include <iostream>


using namespace std;
void getSum(int * arr,int N){
    int sum=0;
    cout<<"Enter "<<N<<" numbers\n";
    for(int i = 0; i < N; i++){
        cin>>arr[i];
    }
    for(int i = 0; i < N; i++){
        sum+=arr[i];
    }
    cout<<"\nSum = "<<sum;
}
int main()
{
    
    int N=5;
    int arr[N];
    getSum(arr,N);
    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

Fuad Endris
18.07.21, 22:03

Thanks

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS