Write a program to enter n elements in an array and display the sum and all the array elements in the array using pointer method

C++ (TurboC)
#include <iostream.h>
#include <conio.h>

int main()
{
    int n,i, s=0;
    cout<<"Enter size: ";
    cin>>n;
    int *a= new int[n];
    cout<<"Enter array elments: ";
    for(i=0;i<n;i++)
    {
    cin>>*(a+i);
    s=s+*(a+i);
    }
    cout<<"Address of array elements are: \n";
    for(i=0;i<n;i++)
    {
        cout<<*(a+i)<<"\t"<<(a+i)<<"\n";
    
    }
    cout<<"\n\nSum of the array elements are: "<<s;
    getch();
    return 0;
}

Try it yourself

Post a Comment

0 Comments