![]() |
My array is not working..
my program generate numbers but it does not store it in the array.. what function must i include..
Code:
#include <stdio.h> |
Re: My array is not working..
You're displaying the contents of rndm_array[idx] before you assign it a value. Also lookup the comma operator, because the code "rndm_array[idx]=i, rand()%40+1" might not do what you think it's going to do.
|
Re: My array is not working..
in fact, m program is to generate 6 random numbers, zen store the results in the array so that the next the regenerated numbers can be compared to the previous one..
|
Re: My array is not working..
What output do you get, and what output did you expect?
|
Re: My array is not working..
i did get the generated random numbers but the array did not keep record of any previous generated numbers... it generate some kind of random numbers by itself.. :(
|
Re: My array is not working..
Well I can't help if you won't answer my questions.
|
Re: My array is not working..
Number[1]=27
Number[2]=9 Number[3]=27 Number[4]=6 Number[5]=19 Number[6]=12 random_array[1]=14 random_array[2]=19 random_array[3]=12 random_array[4]=35 random_array[5]=4 random_array[6]=194 |
Re: My array is not working..
last one is 19..
|
Re: My array is not working..
Your first printf has too many parameters.
Code:
printf ("Number[%d]= %u\n",You do that in a loop, 7 times, then after the loop ends there is an open brace, and you do Code:
rndm_array [idx] = i, rand () % 40+1;Code:
rndm_array [idx] = i;The next loop performs: Code:
printf("\nrandom_array [%d]=",i, rand()%40+1); |
| All times are GMT +5.5. The time now is 11:36. |