Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C PROGRAM PLEASE 1. Write a program that uses a function square to calculate and print the squares of the integers from 1 to 10.

C PROGRAM PLEASE

1. Write a program that uses a function square to calculate and print the squares of the integers from 1 to 10. 2. Write a program that uses a function maximum to determine and return the largest of three integers. Take user-input for the three numbers. 3. Write a recursive function power( base, exponent ) that when invoked returns baseexponent For example, power( 3, 4 ) = 3 * 3 * 3 * 3. Assume that exponent is an integer greater than or equal to 1. Hint: The recursion step would use the relationship baseexponent = base * base exponent1 and the terminating condition occurs when exponent is equal to 1 because base1 = base. 4. The use of computers in education is referred to as computer-assisted instruction (CAI). Write a program that will help an elementary school student learn multiplication. Use the rand function to produce two positive one-digit integers. The program should then prompt the user with a question, such as How much is 6 times 7? The student then inputs the answer. Next, the program checks the students answer. If its correct, display the message Very good! and ask another multiplication question. If the answer is wrong, display the message No. Please try again. and let the student try the same question repeatedly until the student finally gets it right. A separate function should be used to generate each new question. This function should be called once when the application begins execution and each time the user answers the question correctly. 5. One problem in CAI environments is student fatigue. This can be reduced by varying the computers responses to hold the students attention. Modify the program of Problem 4 so that various comments are displayed for each answer as follows: Possible responses to a correct answer: Very good! Excellent! Nice work! Keep up the good work! Possible responses to an incorrect answer: No. Please try again. Wrong. Try once more. Don't give up! No. Keep trying. Use random-number generation to choose a number from 1 to 4 that will be used to select one of the four appropriate responses to each correct or incorrect answer. Use a switch statement to issue the responses. 6. Lets improve the bubble sort program of Homework 7 Problem 1 - use two functionsbubbleSort and swap. Function bubbleSort sorts the array. It calls function swap to exchange the array elements array[j] and array[j + 1]. Remember that C enforces information hiding between functions, so swap does not have access to individual array elements in bubbleSort. Because bubbleSort wants swap to have access to the array elements to be swapped, bubbleSort passes each of these elements by reference to swapthe address of each array element is passed explicitly. Although entire arrays are automatically passed by reference, individual array elements are scalars and are ordinarily passed by value. Therefore, bubbleSort uses the address operator (&) on each of the array elements in the swap call to effect pass-by-reference as: swap( &array[ j ], &array[ j + 1 ] ); Function swap receives &array[j] in pointer variable say element1Ptr. Even though swapbecause of information hidingis not allowed to know the name array[j], swap may use *element1Ptr as a synonym for array[j]when swap references *element1Ptr, its actually referencing array[j] in bubbleSort. Similarly, when swap references *element2Ptr, its actually referencing array[j + 1] in bubbleSort. int hold = array[ j ]; array[ j ] = array[ j + 1 ]; array[ j + 1 ] = hold; Even though swap is not allowed to say precisely the same effect is achieved by int hold = *element1Ptr; *element1Ptr = *element2Ptr; *element2Ptr = hold;

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

DNA Databases

Authors: Stefan Kiesbye

1st Edition

0737758910, 978-0737758917

More Books

Students also viewed these Databases questions

Question

Do you agree with the ninth Circuit Court ruling? Why or why not?

Answered: 1 week ago