ive been tryin to figure out how to program this for nearly 6 hours straight no joke. still i couldnt. Basically i just want to create a program that can separate odd and even numbers from the generated random numbers and then storing it to the array.
my code so far..
btw im using linux emacs for this
Code:
#include <stdio.h>
#include <stdlib.h>
int main()
{
int arr[10];
int ran_num, i, eve_num, odd_num;
srand(time(0));
for(i = 0; i <= 10; i++)
{
ran_num = (10.0*rand()/(RAND_MAX+1.0));
arr[ran_num]++;
}
if (arr[ran_num] %2 == 0)
{
printf("%d\n", arr[ran_num]);
eve_num++;
}
else
{
printf("%d\n", arr[ran_num]);
odd_num++;
}
printf("Even No.s : %d\n", eve_num);
printf("Odd No.s : %d\n", odd_num);
return 0;
}
I also tried swaping codes .. i gave everything i got but still it wouldnt work. I also tried inserting the IF Else statement inside For and its giving me wrong answer too.