Untitled

mail@pastecode.io avatar
unknown
plain_text
2 months ago
1.2 kB
1
Indexable
Never
#include <stdio.h>

void convert_numbers_to_string(int* numbers, int size) {
    char output[100] = {0};
    char sum = 0;
    int zero_flag = 0;
    int status = 0; // 0 - normal, 1 - too large, 2 - sum overflow

    for (int i = 0; i < size; i++) {
        int num = numbers[i];
        if (num >= 10) {
            status = 1; // Number too large
            break;
        } else if (num == 0) {
            zero_flag = 1; // Zero found
            continue;
        }

        sum += num;
        if (sum < num) { // Check for overflow
            status = 2; // Sum overflow
            break;
        }

        output[i] = '0' + num; // Convert number to ASCII character
    }

    if (status == 1) {
        printf("skaiciu masyve yra ne vienazenklis skaicius\n");
    } else if (status == 2) {
        printf("skaiciu suma virsija 8 bitu talpa\n");
    } else {
        printf("%s\n", output);
        if (zero_flag) {
            printf("skaiciu masyve buvo 0\n");
        }
    }
}

int main() {
    int numbers[] = {4, 8, 7, 6, 1, 0, 9};
    int size = sizeof(numbers) / sizeof(numbers[0]);
    convert_numbers_to_string(numbers, size);
    return 0;
}
Leave a Comment