Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
189
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 0.85 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. const int size=100;
  6. void getarray(double[], int&); //funtion prototype
  7. void printarray(const double[], const int);
  8. double sumarray (const double[],const int);
  9. void getarray(double moon[],int&n)
  10. {
  11.     cout<<"enter data. when done, enter '0': "<<endl;
  12.     for (n=0; n<size;n++)
  13.     {
  14.         cout<<n<<":";
  15.         cin>>moon[n];
  16.         if(moon[n]==0) break;
  17.     }
  18. }
  19.  
  20. void printarray(double moon[], int n)
  21. {
  22.     for (int i=0;i<n;i++)
  23.     {
  24.         cout<<i<<":"<<moon[i]<<endl;
  25.     }
  26. }
  27.  
  28. double sumarray (double moon[], int n)
  29. {
  30.     double sum=0;
  31.     for (int x=0;x<n;x++)
  32.     {
  33.         sum+=moon[x];
  34.     }
  35.     return sum;
  36. }
  37.  
  38.  
  39.  
  40. int main()
  41. {
  42.     double moon[size];
  43.     int n,i,x;
  44.     getarray(moon,n);
  45.     printarray(moon,n);
  46.     cout<<"sum = "<<sumarray(moon,n);
  47.  
  48.     return 0;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement