Purpose
The purpose of this project is to help the students to reinforce the knowledge from Chapter 14 of
the textbook.
Objectives
1. Review the top-down design.
2. Understand and apply the concept of recursive thinking.
Problem Description
Write the following 2 functions and test them.
Both of them need to be recursive function.
Sample Run
Note: I use ⌨ symbol to show user inputs, you do NOT need to do ⌨ in your program.
int sum(int n);
// Recursive version to calculate the sum of
// 1 + 2 + .... + n
// For str_length:
// option 1:
int str_length(char s[], int counter);
// option 2:
int str_length(char s[]);
// Recursive version of strlen in C strings.
// It returns the length of the string s[].
// (the null character, '\0', is not counted in the length)
Enter a positive integer: ⌨10
The sum of 1+2+...+10 is: 55
Enter a sentence: ⌨Hello World!
It contains 12 chars, including white spaces
Do you want to have another run? Y/N: ⌨y
Enter a positive integer: ⌨100
The sum of 1+2+...+100 is: 5050
Enter a sentence: ⌨I love programming!
It contains 19 chars, including white spaces
Do you want to have another run? Y/N: ⌨n
Program ended with exit code: 0
Extra Credit
For the function int str_length() , you will get 2 extra credit if you only use 1 parameters, so
the function will looks like this: int str_length(char s[])