Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

1. Write a function that askes the user to enter a positive number. If they enter a negative number warn them and then keep prompting

1. Write a function that askes the user to enter a positive number. If they enter a negative number warn them and then keep prompting them until they enter a positive one. Your function should return the positive number they enter. You are not allowed to use a loop. 2. Write a recursive function for fast powering (it should work faster than the way we wrote it in class). It should take an integer base and exponent; your function should return the base raised to the exponent. For full credit, your function should leverage the fact that x^8 = x^4*x^4 and x^13=x^6*x^6*x--no loops are allowed in this function. 3. Write a function that displays the Jarvis Sequence. The Jarvis Sequence is calculated as follows: a. Take any positive integer n b. Print n c. If n is even, divide it by 2 d. If n is odd, multiply it by 3 and add 1 e. Repeat the this process until n is 1 You are not allowed to use loops in you function. 4. Write a function that takes an array and its size and fills the array with random numbers ranging from 7 to 320 (inclusive). Nope, still not allowed to use a loop. 5. Write a function that takes an integer array and its size and prints its. Make sure to put commas between the elements but not after the last one and you guessed it, no loops. 6. Write a function that takes two integer arrays of the same size and copies the first one into the second one but backward. You will need additional function parameters to accomplish this. NO LOOPS. 7. Write a function that takes an integer x, an integer array, and the arrays size. It should return the number of times x appears in the array. Again, no loops. 8. Finally, write a main function that uses all of these functions to generate the following output (notice that every time a number needs to be entered the function from 1 is used.) Your output should match exactly. You shouldnt need any control flow statements in main.

This is what I have so far:

Please retrict to using no for statements and only #include Thank you!!!

#include

int input(num) { printf("Please enter a positive number: "); scanf(" %i", &num); if(num<0) { printf("ERROR: The number must be positive "); input(num); } return num; } int fastPower(num) {

} int jarvisSequence(num) { if(num%2 == 0 && num != 1) { num = num/2; printf("%i, ", num); jarvisSequence(num); } else if((num%2 == 1) && (num != 1)) { num = (num*3) + 1; printf("%i, ", num); jarvisSequence(num); } else if(num == 1) { printf(" "); } return num; } int randomNumbers(int array[320]) { int i =7; if(i <= 320) { arra[i]= i; i = i +1; } } /*int sizeArrayPrint {

} int twoIntArrays {

} */ int main() { int num = 0; printf("JARVIS SEQUENCE Select a start number "); num = input(num); printf("The Jarvis Sequence for %i is: ", num); printf("%i, ", num); int num_jarvis = jarvisSequence(num); printf(" RANDOM ARRAY Select an array size "); num = input(num); int random_array[num]; randomNumbers(random_array[num]);

}

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

Database And Expert Systems Applications 24th International Conference Dexa 2013 Prague Czech Republic August 2013 Proceedings Part 1 Lncs 8055

Authors: Hendrik Decker ,Lenka Lhotska ,Sebastian Link ,Josef Basl ,A Min Tjoa

2013 Edition

3642402844, 978-3642402845

More Books

Students also viewed these Databases questions

Question

How did you feel about taking piano lessons as a child? (general)

Answered: 1 week ago