Cs 136 Project Language Features For Only This Question You May Use Recursion Do

CS 136 Project:

LANGUAGE FEATURES: For [only] this question, you may use 

recursion

. Do not define global mutative variable. (Write in C)

For these questions, you should recursively use read_int until a READ_INT_FAIL occurs. You may assume there will be at least one int in the input.

When printing ints, you should simply print each one on a newline using “%dn”.

We have provided you with a question q2ex as an example of how to read in the input recursively. This program reads in input and then prints out the numbers in the reverse order that they appeared in the input. You may discuss this example with your fellow students, but not how you could modify it to solve the problems below.

  1. Write a program that reads in ints, and prints the numbers in their original order and then in reverse order.
  2. Write a program that reads in ints, and determines the count of how many numbers were read in. It prints the numbers in reverse order, adding the count to each number.
  3. Write a program that reads in ints, and determines the smallest (lowest) number that was read in. It prints the numbers in reverse order, subtracting the smallest number from each number.

Q2ex as below:

#include “cs136.h”

// reverse_input() reads in integers until READ_FAIL

//  and then prints the integers in their reverse order

// effects: reads from input

//     produces output

void reverse_input(void) {

 int n = read_int();

 if (n != READ_INT_FAIL) {

  reverse_input();

  printf(“%dn”, n);

 }

}

int main(void) {

 reverse_input();

}

I have no idea how to do question 2 and 3. They do not allow global mutation and only recursion. So I’m stuck in here……

"Order a similar paper and get 100% plagiarism free, professional written paper now!"

Order Now