Program1 Design a recursive function that prints each charac

Program1
Design a recursive function that prints each character of a string on its own line. The function should take only one argument, the string to be processed. The string to be processed should be entered by the user.

Program2
Design a recursive function that returns the sum of a range in a list of integers. The recursive function should take three arguments; the list name, the start index of the range, and the end index of the range. To test your function, make a ten element list of small random integers, all from 1 to 20 inclusive. Duplicates are okay. Prompt the user to enter the start and end index for the range. NOTE: The user could enter bad index values. Assume this does not happen.

Solution

// Iterative C program to reverse an array
#include<stdio.h>

/* Function to reverse arr[] from start to end*/
void rvereseArray(int arr[], int start, int end)
{
   int temp;
   while (start < end)
   {
       temp = arr[start];
       arr[start] = arr[end];
       arr[end] = temp;
       start++;
       end--;
   }
}     

/* Utility that prints out an array on a line */
void printArray(int arr[], int size)
{
int i;
for (i=0; i < size; i++)
   printf(\"%d \", arr[i]);

printf(\"\ \");
}

/* Driver function to test above functions */
int main()
{
   int arr[] = {1, 2, 3, 4, 5, 6};
   printArray(arr, 6);
   rvereseArray(arr, 0, 5);
   printf(\"Reversed array is \ \");
   printArray(arr, 6);
   return 0;
}

Program1 Design a recursive function that prints each character of a string on its own line. The function should take only one argument, the string to be proces

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site