Skip to content

Instantly share code, notes, and snippets.

@koetoo
Created April 29, 2019 05:00
Show Gist options
  • Save koetoo/9ab92d69940a399b73f4c466fa7ac53a to your computer and use it in GitHub Desktop.
Save koetoo/9ab92d69940a399b73f4c466fa7ac53a to your computer and use it in GitHub Desktop.
ptrtrain
#include <iostream>
const int MAX=5;
using namespace std;
void convert(double* ptr){
for(int i=0;i<MAX;i++)
*ptr++ *=2.5;
}
int main(){
double sum=0;
double arr[MAX]={10,20,30,50,100};
convert(arr);
for(int i=0;i<MAX;i++){
sum+=arr[i];
cout<<i+1<<" "<<arr[i]<<endl;
}
double avg=0;
avg=sum/MAX;
cout<<"total is "<<sum<<endl;
cout<<"average is "<<avg<<endl;
cout<<"number 1 is "<<arr[0]<<endl;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment