"The sum of the numbers from 1 through 10 equals 55."
Compile and run the code below in your own C environment.
#include <stdio.h>
/* prototypes */
int main(void) {
int input, answer;
printf("Please enter n: ");
scanf("%d", &input);
answer = sum(input);
printf("The sum of the numbers from 1 through %d equals %d.", input, answer);
return(0);
}
/* Please write your function here */
Write a recursive function sumOfDigits() that computes and returns the sum of the digits of an integer number thatโs been passed to the function. Your function should not use any loops!
"The sum of the digits of the number 132436 equals 19."
Compile and run the code below in your own C environment.
#include <stdio.h>
/* prototypes */
int main(void) {
int input, answer;
printf("Please enter n: ");
scanf("%d", &input);
answer = sumOfDigits(input);
printf("The sum of the digits of the number %d equals %d.", input, answer);
return(0);
}
/* functions go here */
Write a recursive function fib() that takes an integer argument n and returns the nth Fibonacci number. Your function should not use any loops! Recall that the first and second Fibonacci numbers are 0 and 1, whereas each subsequent Fibonacci number is the sum of the two previous ones. For example, here are the first 10 Fibonacci numbers:
Compile and run the code below in your own C environment.
#include <stdio.h>
/* prototypes */
int main(void) {
int input, answer;
printf("Which Fibonacci number would you like? ");
scanf("%d", &input);
answer = fib(input);
printf("The %dth Fibonacci number is %d.\n", input, answer);
return(0);
}
/* functions go here */