answersLogoWhite

0

Values are the only factor that can be shuffled in C Programming. You cannot shuffle the array itself, but the values of them can be shuffled and assigned to new element of array. To shuffle the values of an array, the array that will be shuffled must first be initialized or assigned to any values. Also, you must declare one (1) variable that will temporarily store numbers to be shuffled.
Example:
int arrNum [5];
int intTemp;
arrNum [0] = 3;
arrNum [1] = 8;
arrNum [2] = 4;
arrNum [3] = 7;
arrNum [4] = 1;

Using a for loop, assign the first value of the array to any elements to the array. switch these values to shuffle them. To randomize the shuffle, use . Also, try to seed random numbers to randomize each time you run the program.

#include
#include

int main(void) {

int arrNum [5];

int intTemp;

int randArr;

int ctr;

srand(time(NULL)); //seed and randomize number based on time

arrNum [0] = 3;

arrNum [1] = 8;

arrNum [2] = 4;

arrNum [3] = 7;

arrNum [4] = 1;

for (ctr = 0; ctr < 5; ctr++) {

randArr = 0 + rand() % 4; // Assign a random number to randArr from 0 to 4

intTemp = arrNum[randArr];

arrNum[randArr] = arrNum[ctr];

arrNum [ctr] = intTemp;

}


return 0;
}

User Avatar

Wiki User

10y ago

What else can I help you with?

Related Questions

How do you write a C Program to fill up an Integer Array?

Reference:cprogramming-bd.com/c_page1.aspx# array programming


How can you mix up the order of values in a PHP array?

To shuffle an array in PHP is easy to do, all you need to use is the shuffle() function like shown below: &lt;?php $array = array(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); shuffle($array); // array results will be randomly shuffled ?&gt;


What is an array in C-programming?

A type construction: one or more values with the same type and name.


How do you create a 2 multidimensional array of size 22 in C programming?

int x[22][22];


What does it mean when use percent 17 or mod any number in Array in C programming?

I mean %17


Why is c string defined as an array?

Every programming language treats strings as arrays. A C string is defined as being a null-terminated array of characters. A C string that does not have a null-terminator is just an array of character values, but without a null-terminator the onus is upon the programmer to keep track of the array's length.


Is two dimensional array is multi dimensional array in c language?

Yes because multi means more than one in programming, just like it does in English. No isn't that a surprise. Have you read any good programming text books lately.


What is return type of string in c?

In C programming, a string doesn't have a specific return type as it's essentially an array of characters. So, if a function is returning a string, it should be declared to return a pointer to a char (char*), since a string in C is represented as an array of characters terminated by a null character ('\0').


What is an ordered list of data structure using c plus plus?

An ordered list of data in any programming language is simply a sorted array or list. In C++ this can either mean a sorted array, vector, list or forward list.


Which one is used in array programming SISD or MISD?

MISD is used in systolic array.


Some solved question of array in C programming?

Q: What is the very first element of array 'argv' is good for? A: It contains the name of the actual program. Try it: printf ("I am '%s'\n", argv[0]);


What symbol or character determines end of string?

In C programming language, a string is an array of characters which is always terminated by a NULL character: '\0'