# Can someone help me with an array ?

 Daniel CSKA · November 29, 2015 Hello guys, I recently started to study the C++ language and my teacher gave me an assignment to write a code for a program.But I have a a problem. SO what the program is supposed to do is to find the max element of an array and then to print out every 2 elements that are side by side from the array which sum is bigger than the max element.This is what I have so far. #include using namespace std;int main(){    int n;    float a[30], max;    do {        cout << "N=";        cin >> n;    } while (n < 2 || n >28);    for (int i = 0; i <= n; i++)    {        cout << "a[" << i << "]=";        cin >> a;            }    max = a[0];    for (int i = 1; i <= n; i++)    {    if (a > max) max = a;            if ((a + a) > max);            cout << "a[" << i << "]=" << a << ", a[" << i + 1 << "]=" << a << endl;        }        system("pause");    return 0;}

## Replies

 Stevan Zečević · November 30, 2015 #include using namespace std;int main(){int n;float a[30], max = 0;for(int i = 0 ; i < 30; i++){        cin >> n ;        a = n;        if(n > max){           max = n;        }} cout << max << endl;for(int i = 0 ; i < 30; i++){        n = a + a;        if( n > max){              cout  << a  << ", " << a << endl;        }}return 0;}hope this helps
• 1

## C++

131,176 followers