dllbridge

Untitled

May 8th, 2026
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1.  
  2.  
  3. #include<iostream>
  4. //#include "Answer.h"
  5. #include  <string>
  6. using namespace std;
  7.  
  8.  
  9.  
  10.  
  11. struct Answer
  12. {
  13.     int     sum;
  14.     float  mean;
  15.     int   count;
  16.     string text;
  17.    
  18. };
  19.  
  20. Answer Decide(int* ar, int n, string com);
  21.  
  22.  
  23. //////////////////////////////////////////////////////////////////////
  24. int main()
  25. {
  26.     setlocale(LC_ALL, "RUS");
  27.     int A[] = { 2, 6, 7 };
  28.     Answer otvet = Decide(A, 3, "массив А");
  29.     cout << otvet.sum   << endl;
  30.     cout << otvet.mean  << endl;
  31.     cout << otvet.count << endl;
  32.     cout << otvet.text  << endl;
  33. }
  34.  
  35.  
  36.  
  37. //////////////////////////////////////////////////////////////////////
  38. Answer Decide(int* ar, int n, string com)
  39. {
  40.    
  41.     Answer      ans;
  42.     ans.sum   =   0;
  43.     ans.count =   0;
  44.     ans.mean  =   0;
  45.     ans.text  = com;
  46.    
  47.     for(int i = 0; i < n; i++)
  48.     {
  49.         if (ar[i] > 0)
  50.         {
  51.             ans.count++;
  52.             ans.sum += ar[i];
  53.            
  54.         }
  55.        
  56.     }
  57.    
  58.     ans.mean = ans.sum/n;
  59.    
  60. return ans;
  61. }
  62.  
  63.  
Advertisement
Add Comment
Please, Sign In to add comment