1 like 0 dislike
2.3k views

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

 

[Exam] asked in Final Exam
ID: 42300 - Available when: 2018-01-17 14:00 - Due to: Unlimited

retagged by | 2.3k views

32 Answers

0 like 0 dislike
Hidden content!
* ** * * *
* * * **** ** * **

int main()
{
**** ** ** * *** * m, n, charc;
   
* * ***** * *** * ******** *
* ** * * *
* * ******* * * * (i<=50; &m; ++i);
*** *** *** ** *****
* * * **** * *
* * * * * *** * ** * * * **** * * * * &n)
* *** ***** ** ** * ** * ** * * ** *
****** *
***** * ** *******
** * * **** ** **** * *** * 0;
}
answered by (-233 points)
0 0
prog.c: In function 'main':
prog.c:8:12: warning: format '%d' expects a matching 'int *' argument [-Wformat=]
    scanf("%d");
            ^
prog.c:10:9: error: 'i' undeclared (first use in this function)
    for (i<=50; &m; ++i);
         ^
prog.c:10:9: note: each undeclared identifier is reported only once for each function it appears in
prog.c:15:4: error: expected ';' before '}' token
    }
    ^
0 like 0 dislike
Hidden content!
#include ** **** ** *
#include **** * *
#include ******* **

int main()
{
* ** **** **** * * ** * *** * a[999],b[999];
**** * **** * * *** ** ** ****** *
* * * * * ** * *** * *** ** * ** *** ********
*** ***** * *** *
* **** * **** ** * * **** 0;

}
answered by (-16 points)
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include * * ** ****
int main (){
int a[50],i,sum;
*** * ** * * * **
*** ******** ** **** *
if(a[i]!=''){
*** * * * ** * ** *** (i=0;i<a;i++)
***** * * ** ** **** ******* *
* * * * **** *** * ***** * * ** ** * *
** * * * ** * * ** * * * * * * * * ** ** * ** * ** *******
** * * * ******* *** * ** **** **** **** *** * * **
******** ** * ******
return 0;
}
answered by (16 points)
0 0
prog.c: In function 'main':
prog.c:6:9: warning: format '%d' expects argument of type 'int *', but argument 2 has type 'int (*)[50]' [-Wformat=]
 scanf("%d",&a);
         ^
prog.c:7:10: error: empty character constant
 if(a[i]!=''){
          ^~
prog.c:8:15: warning: comparison between pointer and integer
     for (i=0;i<a;i++)
               ^
0 like 0 dislike
Hidden content!
#include<stdio.h>

int main ()
{
* * ****** ** * ** ** * ** a,b;
* ** ** * * * * *** ** **** ** ** *** ** ** ****

* * *** **** * **** *** * *** * *** * ** ********** * * **
* * * * * * * * ***** ***** * 0;
}
answered by (-167 points)
edited by
0 0
prog.c: In function 'main':
prog.c:11:10: warning: format '%d' expects argument of type 'int', but argument 2 has type 'double' [-Wformat=]
 printf("%d",sum);
          ^
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 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
* * * **** * a[50],b[50];
    int i,A[50],B[50],C[51];
    int carry=0,Len_a=0,Len_b=0;
* * *** ***** ** ** ** M,D,sum;
** ** *** * * * ******** * %s",a,b);

* ** * ** ** * * * * ****** * *** ****
    {
**** ** ***** * * * *** * * * ** ** ** ******* * * ** *
* * * *** * * *** * **** * ***** ******* ****** * *
    }
* ** * * ******* * ***** **
    {
* * * * * ** * * * * ** * ** *** ***** * *
* * ********** **** * *** * * *** ** ** *** *********** *
    }
* * *** * ** * ** *
** * ** ****** ** * * ** * ** * *
* * * ** ** * ***** ** ** *
    {
* * * ** ** * **** * * ** * * *** ** * * ** * *
* *** * * * ** * * * **** *** * ***** * *** *
    }
** ** *** * * * ** ** * **
* ** ** * *** * ** ** ** * ** * *** ** ***** *
    {
*** *** * **** ** **** * *** ** * * * * *** * **** ** * * * ** *** ***** **
* *** * * * ****** ****** ** **** *** ** *
* * * * * ** ***** * * * ** * ** **** *** * ***
* * ** ** *** * * ** * * ** ***** ** *
* ** *** *** * *** * * * ** * * ** *** * * *
** ** ** * *** * *** *** ** ** * * *** * ****
    }
*** * * ** * ***** ** ** ** *
    {
****** * * * ** * ** ** * **** **** * ***** * * * *
* *** ******* ***** ***** * ***** * **
* * * ** * ** *** * * ******* * *** * * ** * ** ** *
***** *** ** * *** **** * * ** * * * ** **** *** * * * * *** **** *
** * *** ** ** * ******* *** * * * *** *** *** ***** *** * ** * ** **** *
* ** * ** *** ** ** * ***** ***** * ** * * ******** ** ** * * * *** ** ****
*** * ** * *** * ** * ** * * ** **** ***** * *** ** ** *
*** * ** * *** ***** ** *** **** ** *
    }
***** * ** ** *** *** *** * **
    {
* *** *** ** * * * *** ** * ** *** *
** *** * ** **** * ** * **** * * * ** * *
***** * ******** * ** **** ***** * ***** **** ** **** ** **** * ** * * * ****
**** * *** * * * ********* ** ** * *** * ** ** * * * * *** * * * ** * *
* **** ** * * ** * * ** * *** * * ****** * * * ****** * * ** *** **
** ** **** * **** ** ** * ** * ** **** * ***** ** * * * ***** * * * * ** ** **
* ** * *** * ** * * ** * * **** * ** * **** * ** ** * * * ** ** * * * *
**** * ** * * * * * * * ** *** * **** *
    }
* * ****** * ** * * *
    {
* **** * * **** * * * **** *** **
** ***** *** ** * ** * ** * *** *** ** * ***** *
    }
* * * ** *** * **** * ** * *** *
    {
** ** ** **** ****** ** *** *** ** *** **** ********
    }
*** * **** * * **** ** 0;
}
answered by (-249 points)
edited by
0 0
prog.c: In function 'main':
prog.c:8:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
 scanf("%s",&s1);
         ^
prog.c:9:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
 scanf("%s",&s2);
         ^
0 0
prog.c: In function 'main':
prog.c:9:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
 scanf("%s",&s1);
         ^
prog.c:10:9: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
 scanf("%s",&s2);
         ^
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
int main()
{
** * ** * * ** * * A[50],B[50];
* ** *** * ** * ** * * C[51]={0};
* ** * ** * * * ** * i,j;
* ** *** *** * * * * *** %s",A,B);
* * ** * **** (i=strlen(A)-1,j=0;i>=0;i--,j++)
* ** *** * *** * **
** * ** ** *** ** * * ** * * ******* ** ** * ** *** *
* * * * * ********
***** *** ** * * * * (i=strlen(B)-1,j=0;i>=0;i--,j++)
* ****** * * * *
*** * ****** * * * * * *** * * * *** * * *** *** ** ***
* ** * ** ** * *
* **** * *** *** ** (i=0;i<51;i++)
    {
* ** *** *** *** * * **** * *********** ***** (C[i]>9)
* * ***** * * * * * * * *** *** * ******** * **
* ** *** * ** * ** ** ** ** * *** * ** ** * ***** * ********
** * * ** ** * ** * * * * *** * * ******* ** * * * * ** ***** ********* *
* * * * **** * ** **** * ** * *** * ** * *
* * ** ** *** ****** **
* * ** *** ** *** * * (i=50;i>=0;i--)
    {
** * * *** ** *** * * *** * * ***** * (C[i]!=0)
* * ** * * *** * * ** ** *** * * **
* ******* *** *** * ** **** * ** * ** * ** * **** *** **** (j=i;j>=0;j--)
*** * * ** ** *** ***** **** * * ** *** * ***** * * * ** **** * *** ** * * * ****** * **** * * * **** ** * ** *
*** ** ** * * **** *** * * * * *** ** *** ** * ****** **
** * ** * ** * ** **** **** ** * * ** ** * * **
    }
* *** **** * * * * ** ** 0;
}
answered by (-249 points)
0 0
prog.c: In function 'main':
prog.c:9:14: warning: format '%d' expects argument of type 'int', but argument 2 has type 'size_t {aka long unsigned int}' [-Wformat=]
     printf("%d\n",strlen(A));
              ^
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 0
-----------Re-judge-----------
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
# include <stdio.h>
# include <string.h>
 int main(void)
 {
** *** ** *** * ** **** ** ** a[50],b[50];
** * * *** *** * ** i,j,c[51]={0},zero=1;
* ** ** * *** * * * * ** %s",a,b);

*** * * ** ** * ** * ************* * * * ***
     {
* * ** ** * * **** *** *** *** ** **** ** * * ** * * * ** = a[strlen(a)-i-1]-48;

     }
* * * **** * * * ****** ** * *** * ***
     {
** * * * * ** **** * * * * * * ** ** * += b[strlen(b)-i-1]-48;

     }
** * * ** * * * * * ***** ***** ***
** ** * * *** * *** * * * *** **
* * ** ** *** ** ** ******** ** ******* *** * * ******* ** **
** * * ** * * *** * ** * * **** *** ** * ** *** * * * * * * += c[i]/10;
**** * *** ** * *** ** * * * * *** * ** * ** ** * * * * ****** = c[i]%10;

* * * * ** * ** *

*** **** * *** * ** ** * ** * * ** * **
*********** *** ** **** **** * *
* * ***** ****** ** * ** *** ** **** * * ** * * ***
** * * * **** ** *** ** ** *** * ** * *
** * ******** *** *** * ******* **** * * * * * ** * * *** * * * * * = i;
**** ******* * *** * ** * ** ** *** * ******* *** *** * ** ******* ** *
* ** ** ** * * * * ** * ** * ** **
* * * * * ******* *** ***
* * ***** ** ** * * **** **** **
**** * * * ** * * ** ****** * * * * * * **** *** * *** *
*** ** *** ***** ****** * ** 0;
 }
answered by (-281 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
int Pascal(int a[], int r, int c){}
int main()
{

    int n,i,j;

    scanf("%d",&n);

    if(n<=0)
    {
       printf("0");
    }
    int a[100][100]={{0},{1},{1,1}};

    for(i=3; i<n+1; i++)
    {
* *** * * ***** *** * * * * ** ** *** * * * * * * * * * * * * j<i; j++)
            {
* ** ** ** ** * * ** * * * * ** * * ** ** ** ** *** **** ** ** ** * *** * ****** *** * * **** * **** *** *
* * * * * * * ***** *** * * * ** * * ** * ** * ** **** * * * * * ** ** *** **** ***** *** * * ** *
* * * * * ***** * * * ** *** * ** * * ** *** ** * ** * *** ** * **** *** * * *** * ** * * ** *** * *** *
****** ** **** *** *** ** **** ** * * * * ** * * * ** * *** ** * * * *** ** *** ***** * **** *** ** ** *
* * * * * ** ** ****** ****** *** * * * * ** ** *** ** * * * *** * **** * *** ** * * *** * * * * * * ** * **** if (j<i-1)
**** * ** * ** * * ** * ** * * ** * *** **** ** * ** ** * ***** **** * * * **** * * * * * **** ** ***** **
* ***** * **** ***** ******** * * *** ** **** ** ** **** * *** ***** **** * ** ** * *** * * * *** ** * ** ****** * ** ** * * *** *
******* **** ** * * * * ** * * * * ** **** ** * ** * **** **** **** * ** ** * * *** ** * *** * ** * * *** **
* ** * ** ******* ******* ** * * *** ** ***** * * * * * * * * ** *** * * *** * *** * ***** * * * ** **
** *** * *** * ** * ** ***** ** * **** * *** *** * ** *** ****** * *** ** ** ** * ** * * * *** ** * ** * * * ** **** ** * *
** **** * ** * ******* ** * * *** * ** * * * ** * * * * ** ** *** * * ******* * * **** ** * ** * * * **** ***
********** * **** *** * ** * *** * * * ** * ** * ** * *** * * * **** ** ***** * * ** * * * * * * * ** *** ** * ** *** ****** * *
* * * ** ** **** **** * * ** ** ****** * * * ** ** *
     }
     for(i=1; i<n+1; i++)
     {
** * ******* * * * * ** * * *** * * ** * *** ** * **** *** * * **** * j>0; j--)
* ** * ********** *** * ** * ** * * * * * ***** ****** **** *** ** ** * *
* * *** * *** *** ******* * ** * *** * ** * ** * ** *** * * ** * ** * **** ** * * * ** *** ** * ** * * ** * * * * ");
** * ** ***** *** * * * * *** ** *** ****** *********
* ** * * * *** **** *** * * * * ** ** * * **** ** *** * * ** *** **** * j=0; j<i; j++)
****** * ** * ** * ** **** **** * *** * ** * ** * * * ******** *  if(j==0)
** ****** **** ***** ** ** ** ** ** *** * * * * * ** * * * * ** * ** **** * * * * ** ** * * *** * ** *** * *** * * **
******** * *** * * *** *** * * *** ***** ** * ** ** **** ** * * * * ** * * * * * *
* *** * * *** * ***** * * **** * ** * ** * ** * * ***** * ** ***** * ** ** * ** * ** * ** * * * %d",a[i][j]);
** *** ** * * ** * **** ** * ** * * ** * ** * ** **** *
** * * * ** * * * ** ** * ** ***** ** *** *** * * * *** *** ** **
*** ** ****** *** * ***** * ** * ** ** * * ** * * ** * * * ** * * ***** **
     }
   return 0;
}
answered by (-107 points)
edited by
0 0
prog.c:1:1: error: expected '=', ',', ';', 'asm' or '__attribute__' at end of input
 d
 ^
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 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
* ** *** * * *** string1[50],string2[50];
* * * ** ** **** * arr[51]={0},i;
* * ** * * * ** ** ** **** ** ** ****
* * ** *** *** * **** * * * * ** * * *** *** **
* * ** * * *** * * * * ** ** **** ** *
** * ******* ** ** ****
***** * * * * * ** * * * * ** ** ** ** ** * * **** ****** ** - 1 - i] - 48;
    }
** * * * **** * ** ** * * * * * *** ** *** ****
    {
** * ** * ** * ***** ** **** ** ***** ** ****** * ** ** ***** ** ** - 1 - i] - 48;
* *** * * **** *

* ** **** * * ***** *** ** * **
    {
* * *** * * * * * ***** ****** * * ** *** * ** > 9)
* * * * * * **** **** * ********** * *
**** *** * ***** ** *** * * **** * *** ** ******* * * * * * *** * * * ** *
**** * *** * ** ** ****** *** * ***** * * ** * *** * ** * ***
*** ** * * ** *** **** *** ** * * * * * ****
    }
* * ** * * ** * ** ******* ** * ** ****
    {
** ** * ** * ** * * * **** **** * **** * * **
** *** * * ***** * * **** *** ** * * * * * ** * ** * ** * * *****
* ****** ** ** * * **
* * * ** **** * ** * **
** * * ** * ** * * * ********* * ** ** * **** * *** ***** *
}
answered by (-323 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main()
{
*** **** * **** * string1[50],string2[50];
    
* *** ** ***** ** ** ****** * arr[51]={0},i;
* * ** *** ** * **
* * ** *** *********** ***** * * ***** *** *
**** ** * * * * * * *
****** ******* * * * *** ***** * ** * *** * ** *
    
* ** ** * ***** * **
* ** * * ** ** * * ****** * * * ** ** * * * ***
*** ***** ** * * ** ** * ** ** * *
****** * *** ****** * **** * ** * * * * - 1 - i] - 48;}
    
* ** **** * ***** ** * * * ***** *
    
** * ** * **** ** ***** *** * **** * ** ** - 1 - i] - 48;}

* * * ** * ** ** **
** *** ** *** ** * ** ** *** ** * *** **** ** * *
* * ** * ** ** ******* * * * *** * ** * ***
** * * ***** * ** * ** ***** ** * * ** **
* ****** ** * ******* * *
* * * ** * *** * ***** * * * ****** * ** ** > 9)
****** ** * * ** ****** * * ** ** *** * * **
* ** * ** ** * * ** * * * * * * **** ** **** **
*** * *** * * ***** *
* * * * ** *******
* * * ** * * * * * * *
    
** * * *** ***
** * * ****
* * ** ** * * * **
    
*** * * * *** ** * * ** *
    
** * * * * * * ** ***
* * * * * *** ** * **
* * * ** * *** * * ** * ** *
*** * ** **** ** * ** * * * * * ** *
* **** * * * ** ** *** ** ** * * * *** ** *
** * **** ** ** * **
}
answered by (-284 points)
edited by
0 0
Case 0: Wrong output
Case 1: Wrong output
Case 2: Wrong output
0 0
/usr/lib/gcc/x86_64-linux-gnu/6/../../../x86_64-linux-gnu/Scrt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status
0 0
prog.c: In function 'main':
prog.c:12:10: error: 'i' undeclared (first use in this function)
         (i=0;i<strlen(string1);i++)
          ^
prog.c:12:10: note: each undeclared identifier is reported only once for each function it appears in
prog.c:14:6: error: 'arr' undeclared (first use in this function)
     {arr[i]+=string1[strlen(string1) - 1 - i] - 48;}
      ^~~
0 0
prog.c: In function 'main':
prog.c:9:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
     scanf("%s",&string1);
             ^
prog.c:11:13: warning: format '%s' expects argument of type 'char *', but argument 2 has type 'char (*)[50]' [-Wformat=]
     scanf("%s",&string2);
             ^
0 0
prog.c: In function 'main':
prog.c:14:35: error: expected ';' before ')' token
         (i=0,i<strlen(string1),i++)
                                   ^
prog.c:14:35: error: expected expression before ')' token
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
Welcome to Peer-Interaction Programming Learning System (PIPLS) LTLab, National DongHwa University
English 中文 Tiếng Việt
IP:172.69.6.35
©2016-2024

Related questions

1 like 0 dislike
37 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42302 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 2.1k views
2 like 0 dislike
31 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42301 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 2.1k views
1 like 0 dislike
37 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42299 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 2.5k views
2 like 0 dislike
30 answers
[Exam] asked Jan 16, 2018 in Final Exam
ID: 42298 - Available when: 2018-01-17 14:00 - Due to: Unlimited
| 1.7k views
0 like 0 dislike
8 answers
[Exam] asked Jan 19, 2018 in Final Exam
ID: 43461 - Available when: 2018-01-20 09:00 - Due to: Unlimited
| 465 views
12,783 questions
183,443 answers
172,219 comments
4,824 users