programme c qui permet de determiner si M et N sont amis ou non

#include <stdio.h>

int sum_of_divisors(int n) {
    int sum = 0;
    for (int i = 1; i < n; i++) {
        if (n % i == 0) {
            sum += i;
        }
    }
    return sum;
}

int are_friends(int m, int n) {
    return (sum_of_divisors(m) == n && sum_of_divisors(n) == m);
}

int main() {
    int m, n;
    printf("Enter two numbers: ");
    scanf("%d %d", &m, &n);
    if (are_friends(m, n)) {
        printf("%d and %d are friends!\n", m, n);
    } else {
        printf("%d and %d are not friends.\n", m, n);
    }
    return 0;
}

Explanation: - The program starts by including the necessary header file stdio.h, which provides input/output functions. - The sum_of_divisors function takes an integer n as input and calculates the sum of all its proper divisors (excluding n itself). - Inside the sum_of_divisors function, a variable sum is initialized to 0 to store the sum of divisors. - A for loop is used to iterate from 1 to n-1 (excluding n). - Inside the loop, the if statement checks if n is divisible by i without a remainder. If true, i is a proper divisor of n, and it is added to the sum. - After the loop, the function returns the calculated sum. - The are_friends function takes two integers m and n as input and checks if they are friends. - It calls the sum_of_divisors function for both m and n and compares the results. If the sum of divisors of m is equal to n and the sum of divisors of n is equal to m, the function returns 1 (true), indicating that m and n are friends. Otherwise, it returns 0 (false). - In the main function, two variables m and n are declared to store the user input. - The printf function is used to prompt the user to enter two numbers. - The scanf function is used to read the user input and store it in m and n. - The if statement checks the result of the are_friends function. If true, it prints that m and n are friends. Otherwise, it prints that they are not friends. - Finally, the program returns 0 to indicate successful execution.

Note: This program determines if two numbers are "friends" based on the sum of their proper divisors. Two numbers are considered friends if the sum of divisors of one number is equal to the other number, and vice versa.