Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C language programming Project 3, Program Design 1. Write a program to randomize an array of digits 0 to 9, for instance, 2 3198 475

image text in transcribed

C language programming

Project 3, Program Design 1. Write a program to randomize an array of digits 0 to 9, for instance, 2 3198 475 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 018345 62 9. The program will do 10 times of generating 2 random positions and swapping. Sample output: 6340912857 The program should include the following function where a is the array and n is the size of the array void swap (int all, int n); 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 . 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))

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Oracle Database Foundations Technology Fundamentals For IT Success

Authors: Bob Bryla

1st Edition

0782143725, 9780782143720

More Books

Students also viewed these Databases questions