1234567891011121314151617181920212223242526272829303132333435363738394041 |
- #include <stdio.h>
- #include <string.h>
- #define MAX_LENGTH 52
- void addone(char num[]);
- int main() {
- char num[MAX_LENGTH];
- scanf("%s", num);
- addone(num);
- printf("%s\n", num);
- return 0;
- }
- void addone(char num[]) {
- int length = strlen(num);
- int carry = 1;
- int i;
- for (i = length - 1; i >= 0; i--) {
- int digit = num[i] - '0' + carry;
- num[i] = (digit % 10) + '0';
- carry = digit / 10;
- }
- if (carry > 0) {
- if (length == MAX_LENGTH - 1) {
- printf("\n");
- return;
- }
- int i;
- for (i = length; i >= 0; i--) {
- num[i + 1] = num[i];
- }
- num[0] = carry + '0';
- }
- }
|