Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

#1 (Print an Array) Write a recursive function printArray that takes an array and the size of the array as arguments, prints the array, and

#1 (Print an Array) Write a recursive function printArray that takes an array and the size of the array as arguments, prints the array, and returns nothing. The function should stop processing and return when it receives an array of size zero.

#2 (Print a String Backward) Write a recursive function stringReverse that takes a character array as an argument, prints it back to front and returns nothing. The function should stop processing and return when the terminating null character of the string is encountered.

// Include Files #include #include #include #include

// Project Includes #include

#define SIZE_PROBLEM1 10 #define SIZE_PROBLEM2 30 #define SIZE_PROBLEM3 10 #define MAXRANGE_PROBLEM3 1000

#define SIZE_PROBLEM4 100

// // Functions

//////////////////////////////////////////////////////////////////////////////// // // Function : main // Description : The main function for the CMPSC311 assignment #1 // // Inputs : argc - the number of command line parameters // argv - the parameters // Outputs : 0 if successful test, -1 if failure

int main(int argc, char *argv[]) {

/////// Problem 1 Start ////////////////////////////////////// printf(" -------------------------------------------------------"); printf(" Problem 1 Start");

srand(time(NULL));

int array[SIZE_PROBLEM1]; // array to be printed

// initialize array elements to random numbers for (unsigned int loop = 0; loop < SIZE_PROBLEM1; ++loop) { array[loop] = 1 + rand() % 500; }

puts("Array values printed in main:");

// print array elements for (unsigned int loop = 0; loop < SIZE_PROBLEM1; ++loop) { printf("%d ", array[loop]); }

puts(" Array values printed in printArray:"); printArray(? ? ? ? ); puts(""); printf(" Problem 1 End");

/////// Problem 1 End //////////////////////////////////////

/////// Problem 2 Start ////////////////////////////////////// printf(" -------------------------------------------------------"); printf(" Problem 2 Start ");

// initialize string strArray char strArray[SIZE_PROBLEM2] = "Print this string backward.";

// display original string for (? ? ? ? ) { ? ? ? ? ); }

puts(""); stringReverse(strArray); // reverse the string puts(""); printf(" Problem 2 End");

/////// Problem 2 End //////////////////////////////////////

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

Marketing Database Analytics

Authors: Andrew D. Banasiewicz

1st Edition

0415657881, 978-0415657884

More Books

Students also viewed these Databases questions

Question

u = 5 j , v = 6 i Find the angle between the vectors.

Answered: 1 week ago