may i noe how do i initialise a random number to array?
is this how i do it??
Code:int result[3]={rand( ) % 9 + 1};
may i noe how do i initialise a random number to array?
is this how i do it??
Code:int result[3]={rand( ) % 9 + 1};
No. Either use a loop, and set the value of each element individually, or look up the generate() or generate_n() algorithms in the standard C++ library.
how do i use looping for that? any example coding??
Code:The functionCode:srand()is used to seed the random sequence. Therand()function shall compute a sequence of pseudo-random integers in the range [0, {RAND_MAX}] with a period of at least 2^32. Read more aboutC Programming Language .in the program just change/add each random number to the array.C Program Examples: C Program to generate random numbers.
Think about how to initialize a three-element array without using random numbers. Like if you wanted the array to be set equal to 1, 2, 3.