#include <iostream>
using namespace std;
int main() {
// Write C++ code here
cout << "Pointer and Array program";
int S[]={10,20,-30,40,50};
int *P;
int i,sum=0;
cout<<"\nArray numbers are: ";
for(i=0;i<5;i++)
{
cout<<S[i] << " ";
}
cout<<"\n Sum of all array numbers: ";
P=S;
for(i=1;i<=5;i++)
{
sum=sum+(*P);
P++;
}
cout<<sum;
return 0;
}
output:
Pointer and Array program
Array numbers are: 10 20 -30 40 50
Sum of all array numbers: 90
0 Comments
Post a Comment