subject

A. Write a program to randomize an array of digits 0 to 9, for instance, 2 3 1 9 8 4 7 5 6 0. The random positions of the 10 digits will be generated by randomly swapping two digits in the array 10 times. The program will start with an array of size 10 of elements 0 1 2 3 4 5 6 7 8 9, then use rand() function to generate 2 random positions in the range of 0 to 9 as the index of the digits and swap the two digits. For example, given the array 0 1 2 3 4 5 6 7 8 9, if the two random positions are 2 and 8, then the resulting array of the swapping will be 0 1 8 3 4 5 6 2 9. The program will do 10 times of generating 2 random positions and swapping. Sample output: 6 3 4 0 9 1 2 8 5 7. A. The program should include the following function where a is the array and n is the size of the array void. 1) Name your program key_array. c.2) The main function declares and initialized the array, calls the swap function, and then displays the array. 3) In the swap() function, use rand() function to do 10 times of generating 2 random positions in the range of 0 to 9 and swapping. 4) To use the rand() and time function, you need to include and . B. How to use the rand() function to generate a random number: 1) With the help of rand () function, a number in range of lower to upper can be generated as num = (rand() % (upper - lower + 1)) + lower.2) rand() function generates the same sequence again and again every time the program runs. Use srand() function with time to set seed for rand() function so it generates different sequences of random numbers. Include the following statement at the beginning of the main function; srand(time(NULL)); C. A simple way to encrypt a number is to replace each digit of the number with its position (index) in a key array. A key array is an ordering of the digits 0 - 9, such as 23 19 84 75 6 0. For example, 831 will be encrypted as 412 with the key array 2 319 84 75 6 0 because 8 is at position (index) 4 in the key array, 3 is at index 1, 1 is at index 2. Write a C program that asks the user to enter a positive integer (the integer could be of any number of digits in the range of the integer type) and encrypts the number with a key array that's randomly generated. A sample input/output: Enter the number of digits of the number: 5 Enter the number: 92028 Key array: 2 3 1 9 8 4 7 5 60 Output: 30904.1) Name your program encrypt. c. 2) The user will enter the total number of digits before entering the number. 3) You can use format specifier "%ld" in scanf to read in a single digit into a variable (or an array element). For example, for input 101011, scanf("%1d", &num) will read in 1 to num. 4) Include the swap function from part 1 to generate the key array. 5) As part of the solution, write and call the function replace() with the following prototype. The replace() function assumes that the digits are stored in the array a and computes the replaced digits and store them in the array b. The function uses the key array key to encrypt. n represents the size of the array a and b. void replace(int all, int b[], int key[], int n).6) The main function reads in the input and stores it in an array, calls swap function to generate the key array, and calls the replace function, and then displays the output.

ansver
Answers: 3

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 20:10
Assume the existence of a bankaccount class. define a derived class, savingsaccount that contains two instance variables: the first a double, named interestrate, and the second an integer named interesttype. the value of the interesttype variable can be 1 for simple interest and 2 for compound interest. there is also a constructor that accepts two parameters: a double that is used to initialize the interestrate variable, and a string that you may assume will contain either "simple", or "compound", and which should be used to initialize the interesttype variable appropriately. there should also be a pair of functions getinterestrate and getinteresttype that return the values of the corresponding data members (as double and int respectively).
Answers: 2
question
Computers and Technology, 22.06.2019 21:30
Im doing this last minute and literally none of my neighbors or people that my dad works with use excel so if anyone could me make up an example
Answers: 1
question
Computers and Technology, 22.06.2019 22:30
One of your customers wants you to build a personal server that he can use in his home. one of his concerns is making sure he has at least one backup of their data stored on the server in the event that a disk fails. you have decided to back up his data using raid. since this server is for personal use only, the customer wants to keep costs down. therefore, he would like to keep the number of drives to a minimum. which of the following raid systems would best meet the customer's specifications? a. raid 0 b. raid 1 c. raid 5 d. raid 10
Answers: 3
question
Computers and Technology, 23.06.2019 20:30
What are some settings you can control when formatting columns?
Answers: 1
You know the right answer?
A. Write a program to randomize an array of digits 0 to 9, for instance, 2 3 1 9 8 4 7 5 6 0. The ra...
Questions
question
History, 29.10.2020 17:10
question
Physics, 29.10.2020 17:10
question
Mathematics, 29.10.2020 17:10
Questions on the website: 13722363