比较两个大整数的大小c语言函数
时间: 2023-11-21 14:58:14 浏览: 95
以下是比较两个大整数大小的C语言函数的例子:
```c
#include <stdio.h>
#include <string.h>
int compare(char *a, char *b) {
int len1 = strlen(a), len2 = strlen(b);
if (len1 < len2) {
return -1;
} else if (len1 > len2) {
return 1;
} else {
for (int i = 0; i < len1; i++) {
if (a[i] < b[i]) {
return -1;
} else if (a[i] > b[i]) {
return 1;
}
}
return 0;
}
}
int main() {
char a[100], b[100];
scanf("%s %s", a, b);
int result = compare(a, b);
if (result == -1) {
printf("%s is smaller than %s\n", a, b);
} else if (result == 1) {
printf("%s is larger than %s\n", a, b);
} else {
printf("%s is equal to %s\n", a, b);
}
return 0;
}
```
阅读全文