Средното аритметично на N числа

Да се въведе чрез динамична променлива масив от N числа и да се изведе средното аритметично на положителните.

Публикувано в 12а, 12в с етикети . Постоянна връзка.

9 Responses to Средното аритметично на N числа

  1. krisizdravi95 каза:
    int main(int argc, char *argv[])
    {
      int i, n, *p;
    cout<<"Kolko chisla iskate da vuvedete?"<<endl;
    cin>>n;
    p =new int[n];
    double suma=0, br=0;
    cout << "Vuvedete chislata: "<<endl;
    for(i=0; i<n; i++) {
    cin >>p[i];
    if(p[i]>0)
    {
    br++;
    suma+=p[i];
    }
    }
    
    cout << "Sr.aritmetichno e "<<suma/br<<endl;
    delete[] p;
    
    
    
  2. kr1stiqn1995 каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int i, n, *p;
        cout << "Kolko chisla iskate da vuvedete? ";
        cin >> n;
        p =new int[n];    
       
        cout << "Vuvedete chisla: ";
       
        
        int sum=0, br=0;
        for(i = 0; i < n; i++) {
        cin >> p[i];
        if (p[i]>0){
        br++;
        sum+=p[i]; 
        } 
        }
              
        cout << "Srednoto aritmetichno e: "<<sum/br<<endl;
        cout << endl;
        delete[] p; 
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  3. Gadget каза:
     
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    
    float sredno(int n){
        float br=0;
        float sum=0;
        int *p = new int[n];
        for(int i=0;i<n;i++){
            cout<<"Vavedete chislo ";
            cin>>p[i];
            if(p[i]>0){
              br++;
              sum+=p[i];
            }
        }
        delete[] p;
        return (sum/br);
    }
        
    
    int main(int argc, char *argv[])
    {
        int n;
        cout<<"Vavedete broi chisla: ";
        cin>>n;
        float otg=sredno(n);       
        cout<<"Otgovorut e: "<<otg<<endl;
        
        system("PAUSE");
        return EXIT_SUCCESS;
    }
     
  4. marant каза:
    #include <cstdlib>
    #include <iostream>
    #include <math.h>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
      int i, n, *p;
        cout <<"Kolko chisla 6te ima: ";
      cin >> n;
      p=new int[n]; 
        for(i = 0; i < n; i++) {
          cout << "  Vuvedete chislo nomer: "<<i+1<<endl;
          cin >> p[i];
    } 
      double br=0, sum=0;
        for (i=0; i<n; i++) {
          if(p[i]>0){
          br++;
          sum+=p[i];
        }
            else cout<<endl;
        
      }
        double sr=sum /br;
        cout<<"Srednoto aritmetichno na promenlivite e : "<<sr<<endl;
        
        delete[] p;
      
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
  5. maleboldjia каза:
    Забравих да освободя заделената памет.. 
    
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
        int a, n, *p;
        double sum=0, br=0;
        
        cout<<"Kolko chisla shte vuvejdate: ";
        cin>>n;
        cout<<endl;
        
        p=new int [n];
    
        for (int a=0; a<n; a++) {
            cout<<"a["<<a<<"]= ";
            cin>>p[n];
            if (p[n]>0){
               sum=sum+p[n];
               br++;
            }
        }
        double sr=(sum/br);
        cout<<"Srednoto aritmetichno na poloj. e: "<<sr<<endl;
        cout<<endl;
        
        delete [] p;
    
    
    	system("pause");
    	return 0;
    }
    
  6. LoL каза:
    #include <cstdlib>
    #include <iostream>
    
    using namespace std;
    
    int main(int argc, char *argv[])
    {
    int i, n, *p;
    cout << "Kolko chisla iskate da vavedete? ";
    cin >> n;
    p =new int[n];
    
    for(i = 0; i < n; i++) 
    {
    cout << "Vavedete chislo: ";
    cin >> p[i];
    } 
    int sum=0;
    for (i=0; i<n;i++){
    sum+=p[i];
    }
    cout<<"sumata e"<<" "<<sum<<endl;
    int ar;
    ar=sum/n;
    delete[]p;
    cout<<"srednoto aritmetichno e: "<<ar<<endl;
        system("PAUSE");
        return EXIT_SUCCESS;
    }
    
    

Вашият коментар