how to use an array to input random.......?

any one please

write a program that use an array to input random numbers from users, then traverse the same array checking if number is even or odd, if it is even, ad the number to the sum of even numbers.

if it is odd, add the number to the sum of odd numbers.


i write such a program, but the output is garbage value, i think i can not assign value to array, the value which user enter.

kindly correct the program, if anyone know, thank you





int size, i, sumeven=0, sumodd=0;

printf("enter the size of array \n",&size);


int array[size];

printf(" enter the values of elements\n");

for(i=0; i<size; i++)


scanf("%d", &array[i]);


for(i=0; i<size; i++)



sumeven = sumeven + array[i];


sumodd = sumodd + array[i];


printf("the sum of even values = %d\n",&sumeven);

2 Answers

  • 8 years ago
    Favorite Answer

    I will do the hard part for you

    This is how you put random numbers, from 1 to 100 inside an array


    #include <ctime>

    #include <cstdlib>



    srand (time(NULL));

    // place random numbers into the array

    for(int i = 0; i < NUM_INTS; ++i)


         arry[i] =rand()%100+1;



    This is how you check for even numbers


    If(number % 2==0)


         // NUMBER IS EVEN




         // NUMBER IS ODD



    Hope this helps

  • 6 years ago

    You can use Scanner by writing:

    import java.util.Scanner;

    you then have to name your scanner like:

    Scanner in= new Scanner(;// in is the name of your scanner

    Then you can declare and initialize user input by using:

    .nextInt, .nextDouble, or .next

Still have questions? Get your answers by asking now.