Untitled

mail@pastecode.io avatar
unknown
plain_text
6 months ago
884 B
2
Indexable
Never
#include <stdio.h>

int main() {
    int maxNum = 0;
    int maxSum = 0;



    for (int num = 304; num <= 308; num++) {
        int divisors_sum = 0;
        printf("%d\t", num);
        int divisorCount = 0;

        for (int i = 2; i <= num / 2; i++) {
            if (num % i == 0) {
                divisors_sum += i;
                printf("%3d", i);
                divisorCount++;

                if (i != num / 2) {
                    printf(",");
                }
                if (divisorCount == 4) {
                    printf("\n\t");
                    divisorCount = 0;
                }

            }
        }

        if (divisors_sum > maxSum) {
            maxSum = divisors_sum;
            maxNum = num;
        }

        printf("\t\t%3d\n", divisors_sum);
    }

    printf("\n%d\n", maxNum);

    return 0;
}