Write your question here.
Hi, There is a sequence of numbers , I have to count these items average.If element is bigger than the series average, element should change to 1 and will become new sequence and programm have to count new average.
Information:
n=5
A[i]= 4 5 7 1 2
Result=1.2
This is my code:
#include <iostream>
#include <locale>
#include <fstream>
#include <iomanip>
using namespace std;
int main()
{
int n;
int A[101];
double sum=0,ave=0;
cin>>n;
for( int i = 0; i <n; i++ )
{
cout << "";
cin >>A[i];
sum +=A[i];
}
ave=sum/n;
int i;
if (A[i]>=ave)
{
A[i]=1;
cout << "1"<<A[i];
sum +=A[i];
ave=sum/n;
}
cout << "" << ave;
if (A[i]<=ave)
{
A[i]=A[i];
sum +=A[i];
ave=sum/n;
}
cout << "" << ave;
return 0;
}
Please use code tags. Edit your post, highlight the code and click the <> button on the right side of the edit window.
Right now you declare int i right after computing ave, but you don't initialize it, so A[i] in the next line refers to who knows what? Also don't you need a second loop after computing ave to change the larger values into 1?