Ответ:
Объяснение:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct bigint {
char *data;
size_t size;
int neg;
} bigint;
bigint createBigintFromUnsInt(unsigned long int *n) {
bigint b = {0};
b.neg = 0;
b.size = 0;
b.data = malloc(sizeof(char));
if (*n == 0) {
b.size = 1;
b.data[0] = 0;
return b;
}
while (*n > 0) {
b.data = realloc(b.data, ++b.size * sizeof(char));
b.data[b.size - 1] = *n % 10;
*n /= 10;
bigint createBigintFromInt(long int *n) {
if (*n < 0) {
b = createBigintFromUnsInt((unsigned long int*)n);
b.neg = 1;
} else {
bigint createBigintFromBI(bigint *bi) {
b.neg = bi->neg;
b.size = bi->size;
b.data = malloc(b.size * sizeof(char));
memcpy(b.data, bi->data, b.size * sizeof(char));
bigint createBigintFromChar(char *str) {
if (str[0] == '-') {
str++;
b.size = strlen(str);
for (size_t i = 0; i < b.size; i++) {
b.data[i] = str[b.size - 1 - i] - '0';
bigint createBigint() {
bigint add(const bigint *left, const bigint *right) {
if (left->neg == right->neg) {
b.neg = left->neg;
size_t max_size = left->size > right->size ? left->size : right->size;
for (size_t i = 0; i < max_size; i++) {
b.data
Copyright © 2024 SCHOLAR.TIPS - All rights reserved.
Answers & Comments
Verified answer
Ответ:
Объяснение:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct bigint {
char *data;
size_t size;
int neg;
} bigint;
bigint createBigintFromUnsInt(unsigned long int *n) {
bigint b = {0};
b.neg = 0;
b.size = 0;
b.data = malloc(sizeof(char));
if (*n == 0) {
b.size = 1;
b.data[0] = 0;
return b;
}
while (*n > 0) {
b.data = realloc(b.data, ++b.size * sizeof(char));
b.data[b.size - 1] = *n % 10;
*n /= 10;
}
return b;
}
bigint createBigintFromInt(long int *n) {
bigint b = {0};
if (*n < 0) {
b = createBigintFromUnsInt((unsigned long int*)n);
b.neg = 1;
} else {
b = createBigintFromUnsInt((unsigned long int*)n);
}
return b;
}
bigint createBigintFromBI(bigint *bi) {
bigint b = {0};
b.neg = bi->neg;
b.size = bi->size;
b.data = malloc(b.size * sizeof(char));
memcpy(b.data, bi->data, b.size * sizeof(char));
return b;
}
bigint createBigintFromChar(char *str) {
bigint b = {0};
if (str[0] == '-') {
b.neg = 1;
str++;
} else {
b.neg = 0;
}
b.size = strlen(str);
b.data = malloc(b.size * sizeof(char));
for (size_t i = 0; i < b.size; i++) {
b.data[i] = str[b.size - 1 - i] - '0';
}
return b;
}
bigint createBigint() {
bigint b = {0};
b.neg = 0;
b.size = 1;
b.data = malloc(sizeof(char));
b.data[0] = 0;
return b;
}
bigint add(const bigint *left, const bigint *right) {
bigint b = {0};
b.size = 0;
b.neg = 0;
b.data = malloc(sizeof(char));
if (left->neg == right->neg) {
b.neg = left->neg;
size_t max_size = left->size > right->size ? left->size : right->size;
for (size_t i = 0; i < max_size; i++) {
b.data