Function Implementation and Algorithm Tasks
task 1
question 1: the function convert_score_to_grade takes a enteger as input and returns a character representing the grade. question 2: the returned value will continue to output E until it reaches that value.
task 2
question 1: adds all the digits of a number. question 2: yes, the original approach uses iteration, while the modified version uses recursion.
task 3
return 0;
} // function definition int power_calculation(int base, int exponent) { int temp; if (exponent == 0) return 1; else if (exponent % 2) return base * power_calculation(base, exponent - 1); else { temp = power_calculation(base, exponent / 2); return temp * temp; } }
question 1: calculates the power of a number.
question 2: yes.
task 4
<details><summary>view code</summary>```
#include <stdio.h>
#include <math.h>
int check_prime(int number);
int main() {
int count = 0, value;
printf("twin primes within 100:");
for (int i = 2; i <= 100; i++) {
value = i + 2;
if (check_prime(i)&&check_prime(value)){
printf("%d %d\n", i, value);
count++;
}
}
printf("there are %d twin primes within 100", count);
return 0;
}
int check_prime(int number) {
int flag = 1;
for (int i = 2; i <= sqrt(number); i++) {
if (number % i == 0) {
flag = 0;
break;
}
}
return flag;
}
task 5
1 iterative
2 recursive
task 6
task 7