cHey guy can anyone help me to solve this question because i am begginers i am so sure to use array

C++ write a program to find smallest of 30 integer using array


5 Years
Discussion Span
Last Post by thines01

Yes, make an array and make one single integer variable.
Put the first variable from the array in the single variable and start looping.
If the next variable is LOWER than the the one in the single variable, replace it.
When you get to the end of the loop, the lowest value will be in the single variable.


The program will be

include <iostream>

include <cstdlib>

using namespace std;
int i;
int array[30];
int odd;
int max;
int counter;

int main()
for (int j = 0;j<30;j++)

    i = rand() % 101;


for (int k = 0; k < 30 ; k++)
    cout << array[k] << " ";


for (int l = 0; l < 30 ; l++)
    odd = array[0];
    max = array[0];
    if (array[l] % 2 != 0 && array[l] > max)
        odd = array[l];
        max = array[l];
    if (array[l] % 2 == 0)

    if (array[l] % 2 == 0 && array[l] > max)
        for (int m = 0; m < counter ; m++)
            cout << array[m];


return 0;




@JacobMatthew: Since you're new I'll first explain that since this question is probably homework, the first thing you SHOULDN'T do is "write code".
The code for the example is pretty simple, so an explanation might first be in order.

Secondly, the code you wrote does not do what the OP (original poster) requested and even if it is to be used as just an example, has some serious flaws and should not be used.

OR, if you are asking how to fix that code -- that's another issue and you should (please) start a new thread with your question in it.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.