1 喜歡 0 不喜歡
10.5k 瀏覽

You are requested to help in writing a program to perform addition of two large number up to 50-digits. In C there is no builtin datatype for large number, but we can use characters and array to solve the problem.

Input: The input will contain two positive integers are separated by a blank, the two positive integers do not exceed 50-digits.

Output: Sum.

寫一個程式輸入兩個大數(最大50個位數),計算其總合。C語言不提供大數資料型態,但我們可以用字元和陣列來解決這個問題。

Example input:

999999999999999999999999999999 999999999999999999999999999999

Example output:

1999999999999999999999999999998

 

[考試] 最新提問 分類:Final Exam |
ID: 42300 - 從幾時開始: 2018-01-17 14:00 - 到幾時結束: 無限制

標籤修改 用戶: | 10.5k 瀏覽

32 個回答

0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include ** **** * *
#include * ** ** ** ***
char a[100],sum[200],space,i;
int main()
{
* ** *** ** * * *** ** **

*** * * ** * ***** ** ** **
** * * ** ** *** ** ** * * * * * * * ** *** * '){space=i;}
***** ***** * * * ***

*** * ***** * ** ***** * * **** * **
** * * *** ******* * *** ** *** ** * *** * * ** * **** *
** *** * *** **


* * *** ** * * * 0;
}
最新回答 用戶: (-286 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
***** ***** **
* ** * *
*** ** * * ** * *** *
int main(){



}
最新回答 用戶: (-32 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
#include<string.h>
int main (void)
{
** *** * ** * * num1[51],num2[51];
* * *** * * * * * *** i,m;
******** ** ** * * * arr[51]={0};
** ** ** ****** ** **
* * * **** *** ** * * * ** * %s",num1,num2);
   for (i=0;i<(strlen(num1));i++)
    {
* ** ** ***** *** * * ****** * * * ** * ** ** **** *** ** * ** **
    }
* *** ** ** * * *** * (i=0;i<(strlen(num2));i++)
*** * *
* * * *** **** **** ** * * ****** ** ** ** ** * * * ********* ** **
** * * ** * ******* *
*** ** * * * ** * ** (i=0;i<=50;i++)
** ** * * * * **** * *
** ** * * * **** ** * * ** * **** * * * *** * *
* **** *** *** *** *** * *** ****** *** ***
* * * * ** *** * * **** ***** ** * * *** ** ** ** * * *** *
* * * * * * * *** * * ** * * ** ** *** * * * ** * **** ** * * * *******
* ** ** ** ***** ** **** ***** * **
    }
*** * * *** * ** ** * **** ***
    {
* * **** *** *** ** * * *** ** * * * * *** *** **
*** ** * * * *** *** * * *** * * * *** ***
****** * * * * * ** * * * **** * ** * * ** * * * *
** ** * * ****** ** ** * * * ** * * * *
* *** *** **** ** ** * ** * * ** * * * ** * ******* * *
*** * ******** ** *** ** * * * * **
*** * ** * * ** * ** ** *** **** * * ** * * **** *** *** * *** ** **** * *
* * ** * ** * ** ** * * * * *** * **** ******* * * *** ** **** * * * * ** *
** ** * ** **** ******* *** * * * ***
    }
*** * ** * * ** *** *** 0;

}
最新回答 用戶: (-168 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
#include<string.h>
#define n 50
int main()
{
******** * **** ***** a[n],b[n];
** * * ** * **** ** * * * **** * ** * ****
* *** *** * * *** * l1,l2;
* ** ** * ** * * * ***** * i=0;
* ** ** ** * * * *** * **
****** * **** ***** ***
** **** ** * * * ****** **** * **
* ************ * * ******* ** * * *** *
* * * ***** ** ** * * * *** * **** *** * ** * * * *



* * ** * * ** * **** ** * *** ** * ** * ** **** ** **** * ** * * * *** * *** * * *** * *





***** * ** * ** * *** * * * ** * *** * *** ****



}
最新回答 用戶: (-329 分)
修改於 用戶:
0 0
prog.c: In function 'main':
prog.c:7:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
     scanf("%s%s",&a,&b);
             ^
prog.c:7:15: warning: format '%s' expects argument of type 'char *', but argument 3 has type 'char (*)[50]' [-Wformat=]
     scanf("%s%s",&a,&b);
               ^
0 0
prog.c:28:1: error: expected identifier or '(' before '}' token
 }
 ^
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
** * * * * *** ** * * a[50];

**** * ** **** * **** *** * * b[50];

** ** * * **** c[51] = {0};

* **** *** * ** * ** ** *** * * * a, b);

* * ** * **** i = 0;

** ** * *** ** *** ** ** len_a = strlen(a);

****** * *** * ** * len_b = strlen(b);

* * * * * *** = 0; i < len_a; i++)
* **** *** **** * ** * * ** ** *
* * * * **** **** **** * * ** ** * = a[len_a - i - 1] - '0';
* * * *** * * *** ****
******* ** *** ** * ** ** * ** = 0; i < len_b; i++)
* * ******* * * * * *
* * * ** * ** * * **** * * * += b[len_b - i - 1] - '0';
*** * * *** * * *

* * *** * * *** ** *** ** = 0; i < 51; i++)
* * * ** * *** ***** **
* ** ** ** ***** * *** ** *** ** *** * > 9)
*** * *** *** * * * * * ** * * *** ******* *
*** ** ** * * ** * ***** * ** *** * * ***** * ** *** * ****** * + 1]++;

*** * ** * **** *** * *** ** ** * **** * ** ** *** * * * ** * %= 10;
* ** * *** ******** * **** * ** * *** **** *
* ***** ** * **

* * * *** * **** * nonzero = 0;

*** ***** ** * *** ** ** * = 50; i > -1; i--)
* ** *** * * * * ***
* * * * * ***** * ** * * ** **** * * ** ** * *** != 0)
*** * * * * *** ** * * ** ** * ** *** * **** **
**** * * ******** * * ** * * ***** * * *** ***** *** * ** * = i;

****** ** * * ***** ** * * ** ** * ** * * * * ******* * * *
* * * * * ** * *** ******** * * ** * * * **
    }

* *** * **** * * *** = nonzero; i > -1; i--)
** *** *** ** ****** *
*** * ** * **** * * * ** ** **** ** ** *** *** * ***** * **** * c[i]);
** ** * * * **** * * *
***** ***** * **** * * ** ***** 0;
}
最新回答 用戶: (-285 分)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>
#include<string.h>

int main()
{
    int i,e,begin=0;
    char a[51],b[51];
    int c[52]={0};
    scanf("%s",a);
    scanf("%s",b);

* * ** * ** * *** ** * * ** * * * ***** *** ** *** ** *** * * **
    for(i=0;i<strlen(a);i++)
** ** * **** * * ** * **** * * * ***
* * * * * * * ** * * * * ** * * ** *** * ** ** * * * * *** ** ***
* ** * ********* * * ** ***** * ** * **** * **
    for(i=0;i<strlen(b);i++)
* * ** * ****** ** ** ** * *** * ** ***** **
* * * *** *** *** ** ** * * * *** * *** *** *** * * * ** * ******
** * * ** * ** **** ** *** * ** * * * * * *
    for(i=0;i<50;i++)
* * ** ** ** ** ** ** *** ******* ***
* * * ** * * * ** ** * * * * **** * **** *** ** *** * ******* > 9)
** * ** * **** ** ******* * * * *** * ****** * * * ** * * ** ** *** * ***** * * ***
** * *** * * *** ***** *** ***** ** *** * * **** * * * ** * *** * * * * **** ** ** ** ** **
****** * ** * ** * * * ** ** * * ** * *** * * * ** ** ** * * * ** *** *** * ** ** ** ** *
** ************* *** * * * ** * * * * ** * ** ** *** * ** ******* ******* ** * ** ** **
* ** * * * * **** * * *** **** ** * ** *
    for(e=51;e>0;e--)
*** ** * * * *** ** * * * * * * ** ****
* * ** * ** ** * **** * * * * ** ** ** *** * **** * * ** ** * ** * * * != 0)
**** * *** * ** *** *** ** ** * * ** * * * * * *** * * *** ****** ***** * **** ** *
** * * * * ******* * * ** * ** * * ** * ** **** * * * * * **** * * ** **** * ** ** *** ** * *
****** * *** ** * *** *** * *** **** ** * * * * *** ** * ** ****** * ******** * ** ** * ******** * ** **
* ** ***** * * * ** * * ** *** *** * **** ***** * ** * * ** ****** ***** ** * * * ** ** **
**** * ** * * * * ** ** * **** *
* * * * * * * * * ***** *** * * *** ** * * ** ** *** *** * ** *
    for(i=begin;i>=0;i--)
** ** * ** ** **** *** * ******* * * *
* ** * **** * * * * * ********* ** ** * ** ** ** * ** * * ** ** *** * ** *** * * * *
***** ** * * * * *** ** * * ** * * * *
}
最新回答 用戶: (-301 分)
修改於 用戶:
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include <string.h>
int main()
{
****** **** * ** * * * i,j,k,l;
** * * ** ** * ** ** * *** a[100];
* *** ** * * * ** *** * b[100];
***** * ** **** *** ** * *** * ** * ****
*** * ** * ****** * * *** * ***** **** * && * **** * * ** *
* * *** * **** * * **** *
** ** * ** * ** ** * * ** * * * * * ** ******** ** ** ** * **** **** ** * ***
* ** ** **** * * * * *
** ** *** * * * ** 0;
}
最新回答 用戶: (-229 分)
0 0
prog.c: In function 'main':
prog.c:9:12: warning: integer constant is too large for its type
     if (a==999999999999999999999999999999 && b==999999999999999999999999999999)
            ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:9:10: warning: comparison between pointer and integer
     if (a==999999999999999999999999999999 && b==999999999999999999999999999999)
          ^~
prog.c:9:49: warning: integer constant is too large for its type
     if (a==999999999999999999999999999999 && b==999999999999999999999999999999)
                                                 ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.c:9:47: warning: comparison between pointer and integer
     if (a==999999999999999999999999999999 && b==999999999999999999999999999999)
                                               ^~
0 喜歡 0 不喜歡
內容已隱藏
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>


   int main()
   {
* ** ** ** ** **** * * * * a[50],b[50];
* * **** ** * ******* * ** ** c[51];
***** ***** ** ** * * * ** *** *** * * n1, n2;
* * * * * * ** *** ***** * ** ** * * i,j;

** ***** ** * ** * * *** ** *** * *** * ** ***
* * * * * * *** * ** ** * ** * *** ** *

* * * * *** * ** ** * **** *** *** ********* **
       {
* ** * ** * * *** *** * *** ** ** *** **** **** * **** * * ** * * ****** ** );
* * ** ** ** * *** * * *******

*** ** ** ***** ***** ** * ****** ** ** * ** **** *** **
* *** * * * * ** ** *** * * *
* ** ** *** * * * * ** * **** * * ** ** * ** **** ** *** * *** *** *** * * **** * *** b[i]);
* *** ** *** * * ** * * ** ** ****



* * * * *** * *** **** ** * ** * * * * * * ****
* ***** * *** * **** * * * ** **
* * ** ****** * * *** * * ***** **** ** * ** * * ** * ** ***** ** ** *
**** * * ** ** ** ** *** * * * * * * * *
** * ********* * ** * **** ** * * *** * ** *
* **** ** * ** *** * ***** ** **** **
** * ** * * ** *** * ***** * ** *** * * ** ** * ****
* * * ** ** ** * *** **** * ****

** * * ** * * ***** **** * * ** ******* * *
* * * * * *** ****** * * * *** ** **
** * * **** ** ****** ***** ** *** * * * *** * * * * * *
* * * *** ** * * *** **** *** *** *** *** **** ** ****** *
       }

**** * **** ** * ** **** * * **** *** ** * ***********
       {
*** ** ** ** * ** * *** * * * ****** *** *** * * ***** *** * * ***** ** * *
       }

** * *** * * **** * * * ** * * * ** * **
* * * * **** * *** * * **** ** * ** ***** **** **** *
* * ** * ** * * * ** * * * * * * * **** ** * ** ** ** * * * ****** ** * ** *
***** **** ** * ** * ** *** * *** *** **


    return 0;
}
最新回答 用戶: (-193 分)
修改於 用戶:
0 0
prog.c: In function 'main':
prog.c:13:14: warning: format '%[^
   ' expects argument of type 'char *', but argument 2 has type 'int (*)[50]' [-Wformat=]
    scanf("%[^\n]*c%",&a);
              ^
prog.c:13:19: warning: spurious trailing '%' in format [-Wformat=]
    scanf("%[^\n]*c%",&a);
                   ^
prog.c:14:14: warning: format '%[^
   ' expects argument of type 'char *', but argument 2 has type 'int (*)[50]' [-Wformat=]
    scanf("%[^\n]*c%",&b);
              ^
prog.c:14:19: warning: spurious trailing '%' in format [-Wformat=]
    scanf("%[^\n]*c%",&b);
                   ^
prog.c:17:17: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
    for(i=strlen(a),j=0;1<=0;i--,j++)
                 ^
In file included from prog.c:4:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
prog.c:22:18: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
     for(i=strlen(b),j=0;1<=0;i--,j++)
                  ^
In file included from prog.c:4:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
0 0
prog.c: In function 'main':
prog.c:14:18: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
        n1=strlen(a);
                  ^
In file included from prog.c:3:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
prog.c:15:18: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
        n2=strlen(b);
                  ^
In file included from prog.c:3:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
prog.c:19:20: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
            scanf("%d",a[i] );
                    ^
prog.c:24:20: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
            scanf("%d", b[i]);
                    ^
prog.c:46:21: warning: format '%d' expects a matching 'int' argument [-Wformat=]
            printf("%d");
                     ^
0 0
prog.c: In function 'main':
prog.c:19:20: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
            scanf("%d",a[i] );
                    ^
prog.c:24:20: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int' [-Wformat=]
            scanf("%d", b[i]);
                    ^
prog.c:46:21: warning: format '%d' expects a matching 'int' argument [-Wformat=]
            printf("%d");
                     ^
0 喜歡 0 不喜歡
內容已隱藏
#include ** *** **
#include * * ** *
#include ** ***** * ***
int main ()
{
* ** ** *** ** ** * * * i,n,m,c=0;
***** **** *** * * *** A[60]={0};
** * * * * **** ** * ****** * **
** ** **** ** ** * * * ("%s ** * * *
* *** * * **** * ***** * *** * ** * ** **
* * * ** * ** * * ** *** ***** * 0;
}
最新回答 用戶: (-32 分)
修改於 用戶:
0 0
prog.c: In function 'main':
prog.c:14:23: warning: passing argument 1 of 'strlen' from incompatible pointer type [-Wincompatible-pointer-types]
     for (i=0;i<strlen(A);i++)
                       ^
In file included from prog.c:2:0:
/usr/include/string.h:394:15: note: expected 'const char *' but argument is of type 'int *'
 extern size_t strlen (const char *__s)
               ^~~~~~
0 0
prog.c: In function 'main':
prog.c:11:5: error: expected ';' before 'return'
     return 0;
     ^~~~~~
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
0 喜歡 0 不喜歡
內容已隱藏
#include<stdio.h>

int main() {
    char a[50], b[50], sum[50];
    int i,j,tmp=0;

    for(i=0;i<50;i++) {
* *** ** ***** * ***** * * *** **** ** *** * * *
    }

** ** * * ** * * *** * * a);
***** * ** *** ** * * * * ** * *** *** * b);

    for(;;) {
** * * ** * * ** ** *** * ** ******* * *** * {
* * **** *** * ** *** ** **** ** ** *** ******* * ****** *** * *** * * ***
** * *** ** * **** * * ** ** * * * ** *** * ** *** * * ** ** **
* * ***** * * * * * *** * * * * ** * * * * ** * * * * * * *
* * *** *** *** * **** * **** * *** * * ** **** *
*** * ** * * ** * ** ** ** *** * ** * * * {
** * * * * *** * * * ** ** ** **** * ** * * *** * ** ** * *
* ** * * *** * ** * *** ** * ** *
    }

    for(;;) {
*** * **** * * *** *** * *** *** * * * * * * * {
* ** ** **** * ** * * ** * ****** * ** **** * ** ** **** ******* * * * *** ***
* * ** ***** ** *** *** * * ***** ** *** ** * * *** * *** ** * ** * * **** *
**** ***** ** **** *** * * * * * ** ** * ** * * * **** *
* **** ** * * ** ** * *** *
*** ** * * *** * * ** ***** ** * * * ****** * * {
****** ********* *** * ***** * ** * *** * ** ***** * * * ** ** * ** *
** * ** ** * ** ** ***** ** ** ** **
    }

** ***** *** * * * * ** * ** ** ***** {
** ** ********* * *** ** *** * * ** * ** *** * *** ** && a[i]<=57) {
* * *** ** * ** * *** * *** * * ** **** * * *** ** ** ******
* ** * * * *** * ** ** ** *** ** ***** * *
* * **** ** * * *** * * ** ***** ** *** *** ***** * * *** && b[i]<=57) {
** * * ** * * ** * ** * * ** ** ** * * ** *** * **** ** * ** ****** **
** ** * *** **** *** * *** * * * **
    }

    for(j=50;j>0;j--) {
* * **** * * * ** * * * * * * ******* * *** *** **** * * {
* * * * * * * * ******** ** * * ***** * * ** **** * ** ***** * * * ** ****
* * ** ** * **** * * ** * ** * * * ** ***
*** ** **** ** * * ** * *** * ** *** if(sum[j]+a[j]+b[j]==10) {
* **** ** * ** * ** **** ** **** *** * * ** * * **** * * **
** * * ** * * * ** *** ** ** ** ** * * ****** * ** ** ** ** *
* *** * ** ** * ** * **** * ******** * **** *
** * * * * * ** * ** * *** * ** ** ****** if(sum[j]+a[j]+b[j]>10) {
* * *** ** **** *** ** * * * ** ***** * ** ** ** ******* **** * * *** * * * *** *
* *** * * ******** * *** * ** ** * ** * **** * **** * * * * * * *
** ** * * * * *** ** * ***** *** ** * *
    }

    for(j=0;j<50;j++) {
* * **** *** * *** *** * * *** ** * *** ** {
* ** ** * * * ** ** **** * * *** * * ***** * * *** ***** * ** * *
** * ** *** * *** *** * **** **** *** ***
    }

    for(;j<=49;j++) {
** * * ** ** * * *** * ** *** * * *** * ** * ** ***** * sum[j]);
    }
}
最新回答 用戶: (-120 分)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.130.47
©2016-2025

相關問題

1 喜歡 0 不喜歡
37 回答
[考試] 最新提問 1月 16, 2018 分類:Final Exam |
ID: 42302 - 從幾時開始: 2018-01-17 14:00 - 到幾時結束: 無限制
| 10.4k 瀏覽
2 喜歡 0 不喜歡
31 回答
[考試] 最新提問 1月 16, 2018 分類:Final Exam |
ID: 42301 - 從幾時開始: 2018-01-17 14:00 - 到幾時結束: 無限制
| 9k 瀏覽
1 喜歡 0 不喜歡
37 回答
[考試] 最新提問 1月 16, 2018 分類:Final Exam |
ID: 42299 - 從幾時開始: 2018-01-17 14:00 - 到幾時結束: 無限制
| 10.1k 瀏覽
2 喜歡 0 不喜歡
30 回答
[考試] 最新提問 1月 16, 2018 分類:Final Exam |
ID: 42298 - 從幾時開始: 2018-01-17 14:00 - 到幾時結束: 無限制
| 8.1k 瀏覽
0 喜歡 0 不喜歡
8 回答
[考試] 最新提問 1月 19, 2018 分類:Final Exam |
ID: 43461 - 從幾時開始: 2018-01-20 09:00 - 到幾時結束: 無限制
| 2k 瀏覽
12,783 問題
183,442 回答
172,219 留言
4,824 用戶