Fading Coder

One Final Commit for the Last Sprint

Home > Tech > Content

Function Implementation and Algorithm Tasks

Tech Sep 22 1

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

Related Articles

Understanding Strong and Weak References in Java

Strong References Strong reference are the most prevalent type of object referencing in Java. When an object has a strong reference pointing to it, the garbage collector will not reclaim its memory. F...

Comprehensive Guide to SSTI Explained with Payload Bypass Techniques

Introduction Server-Side Template Injection (SSTI) is a vulnerability in web applications where user input is improper handled within the template engine and executed on the server. This exploit can r...

Implement Image Upload Functionality for Django Integrated TinyMCE Editor

Django’s Admin panel is highly user-friendly, and pairing it with TinyMCE, an effective rich text editor, simplifies content management significantly. Combining the two is particular useful for bloggi...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.