Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- const int size=100;
- void getarray(double[], int&); //funtion prototype
- void printarray(const double[], const int);
- double sumarray (const double[],const int);
- void getarray(double moon[],int&n)
- {
- cout<<"enter data. when done, enter '0': "<<endl;
- for (n=0; n<size;n++)
- {
- cout<<n<<":";
- cin>>moon[n];
- if(moon[n]==0) break;
- }
- }
- void printarray(double moon[], int n)
- {
- for (int i=0;i<n;i++)
- {
- cout<<i<<":"<<moon[i]<<endl;
- }
- }
- double sumarray (double moon[], int n)
- {
- double sum=0;
- for (int x=0;x<n;x++)
- {
- sum+=moon[x];
- }
- return sum;
- }
- int main()
- {
- double moon[size];
- int n,i,x;
- getarray(moon,n);
- printarray(moon,n);
- cout<<"sum = "<<sumarray(moon,n);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement