Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Question 29 (Programming) An n by n magic square is a square whose columns, rows, and main diagonals all have the same sum. mamely n(n'+

image text in transcribed

Question 29 (Programming) An n by n magic square is a square whose columns, rows, and main diagonals all have the same sum. mamely n(n'+ l)2 Question 31 (Programming) For example, for n=3 each sum should be 15 and the example below is a magic square. a) Write the definition of a C function that has the header: 8 1 6 15 3 5 7 15 4 9 2 15 15 15 5 15 15 void counters (int list, int n, int count, int k) Assume that each of the n values in list is an integer in the range 0 to k inclusive and that the Write a C program to read a number, N and then read N2 values, N on each line and stone these values in an array. It should then determine whether the values form a magic square. array count is of size k+l For example your program could read the following data values and output them with a message "These values form a magie square. If the values read do not form a magic square, the message should read "These values do not form a magic square After calling the function counters, each element, count[i will contain the number of values in list that are less than or equal to i Make sure that the function counters initializes the count array to contain only 0's. An example. If list contains {2, 5, 3,0, 2, 3, 0, 3)and k-5, then at the end of the call to 81 6 3 5 7 4 92 counters, the array count will contain {2, 2,4,7,7,8 Your peogram should be able to handle any value of N between 2 and 100 b) Write the definition of a C function that has the header: Question 30 (Programming) You are planning a long car trip with your friend. To help pass the time your friend proposed the following bet. You are to keep track of the last two digits of the license plates of cars you see on the road. He will bet you $10 that within the next twenty cars that pass, the same two digit number will occur more than once. (If a number repeats itself your friend will win the S10, otherwise you will win the SI0).You are not sure whether this is a good bet or not and void CountingSort (int in, int n, int out, int k) This function uses the counters function of part (a) to sort an array into ascending order a program to simulate the outcome Note that the value of counti] indicates the starting position for all values greater than i in the sorted array, "out". Write a program that will simulate this game by generating 20 random numbers and determining wbether you win or lose the wage. Perform this simulation 100 times and determine the total amount of money you would have won or lost. Question 29 (Programming) An n by n magic square is a square whose columns, rows, and main diagonals all have the same sum. mamely n(n'+ l)2 Question 31 (Programming) For example, for n=3 each sum should be 15 and the example below is a magic square. a) Write the definition of a C function that has the header: 8 1 6 15 3 5 7 15 4 9 2 15 15 15 5 15 15 void counters (int list, int n, int count, int k) Assume that each of the n values in list is an integer in the range 0 to k inclusive and that the Write a C program to read a number, N and then read N2 values, N on each line and stone these values in an array. It should then determine whether the values form a magic square. array count is of size k+l For example your program could read the following data values and output them with a message "These values form a magie square. If the values read do not form a magic square, the message should read "These values do not form a magic square After calling the function counters, each element, count[i will contain the number of values in list that are less than or equal to i Make sure that the function counters initializes the count array to contain only 0's. An example. If list contains {2, 5, 3,0, 2, 3, 0, 3)and k-5, then at the end of the call to 81 6 3 5 7 4 92 counters, the array count will contain {2, 2,4,7,7,8 Your peogram should be able to handle any value of N between 2 and 100 b) Write the definition of a C function that has the header: Question 30 (Programming) You are planning a long car trip with your friend. To help pass the time your friend proposed the following bet. You are to keep track of the last two digits of the license plates of cars you see on the road. He will bet you $10 that within the next twenty cars that pass, the same two digit number will occur more than once. (If a number repeats itself your friend will win the S10, otherwise you will win the SI0).You are not sure whether this is a good bet or not and void CountingSort (int in, int n, int out, int k) This function uses the counters function of part (a) to sort an array into ascending order a program to simulate the outcome Note that the value of counti] indicates the starting position for all values greater than i in the sorted array, "out". Write a program that will simulate this game by generating 20 random numbers and determining wbether you win or lose the wage. Perform this simulation 100 times and determine the total amount of money you would have won or lost

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

More Books

Students also viewed these Databases questions

Question

Explain the first views of mental disorders.

Answered: 1 week ago

Question

Why We Listen?

Answered: 1 week ago