1 like 0 dislike
13.9k 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 | 13.9k views

32 Answers

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

int main()
{
* ** i, j, k, t=0;
* * x, y, z, c[51]={};
* ** * a[51]={}, b[51]={};

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

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

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

** *** * ***

* * * * * *** * *

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

**** ** * * * ******** * *
 {
* **** ****** ** ** *
* ** ** * ***
***** * *** ** ** ** ** *
** * * *** * **** ** **
* * ** ****
 }
* *** ** *** * * *
** ** ** * *
 {
* ** * ******** ****** ******
** ** * *
 }
}
answered by (-66 points)
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Wrong output
0 like 0 dislike
Hidden content!
#include * * *
#include * ** * ** *

int main()
{
*** ** * * ** ** **** * n1, n2, ans;
** ** * * ** * ***** ** * ** * ** * *** * ** *
***** * ****** ** ** ** + n2;
** ** * *** *** *** ** *** **** **** ans);
** *** * * * * * ***** ** * 0;
}
answered by (-168 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 <stdlib.h>
#include <string.h>

int main()
{
**** * * *** * * * ** * a[50],b[50];
* ** * * ** ** *** **** * * * %s",a,b);
* * **** * **** * * ** * c[51] = {0},i,j,len_a = strlen(a),len_b = strlen(b),x;
* * * ** * * ** * **** = 0 ; i < len_a ; i++)
*** *** * * ** * ** *** * * **** * ** * = a[len_a-1-i]-'0';
*** * **** **** * ***** = 0 ; i < len_b ; i++)
** * *** ** *** ***** * *** * ***** ** ** += b[len_b-1-i]-'0';

*** * *** * * ** * * ** = 0 ; i <= 50 ; i++)
** * ** * * *** ** *
** * *********** * ** *** *** ** ** **** * > 9)
*** * * ** *** * **** * * **** * * * * *** ******
** * * * *** * * * * *** * * * * ***** ** ** * * * **** * ** * * *
* * ** ** *** ******** * **** ** * * ** ** ** ** *** *** ** * * = c[i]%10;
**** * * **** ** **** *** * * ***** *** *
** * * * *** ***
* ** ****** ** * ** ** *** = 50 ; i >= 0 ; i--)
** **** ** * * * * * **
** * *** *** * ** * *** * ***** ******* ** **** * ** * != 0)
*** * * * * * * * ** ** ** ** ** *
* *** * *** * * ** * * * * * * * *** * * * ** * * *** = i;
** ** * * ** * * * *** * * * * *** * * * ** ** ** *** ** ***
** * ** * * ******* ** * * * *** ** ***** * *** *
*** * * * * ** * * *
** ** * * **** *** ** = x ; i >= 0 ; i--)
* *** * * * * * * * * *
* * * * * * * * ** * ** * ******* * * ** * * ** **** * **
* ******* * * ** ****



* ***** *** * ** *** 0;
}
answered by (-255 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()
{
    char string[1000],reverse[1000];
    int index=0,len,wordstart,wordend,i;
    fgets(string,1000,stdin);
    len = strlen(string);

    wordstart=len-1;
    wordend=len-1;
    while(wordstart>0)
    {
****** * **** ** **** * * * * ** ** ** * * ****** * ')
* * * * ** ****** * ** * ***** * * * * **
* * ** * ** ***** ** * *** ** * **** * * **** ** * ** ** ** * * ****
** **** ** * * *** ** * * * **** *** ** ** * * * * ** * * * * * * **** * * *
* ** * * * * * * * ***** * *** ******** ** * *** *** * *
* * * * ** * * * * ** ** ** *** ** **** * * ** **** * * ** ** ****** *** ****
** * * *** * ***** * * * * * ** ********** ** ** ** * *** ** * * ** **** * *** * * *** *** *
* * ** * * ** ****** * *** * * * * *** ** * * ** * **** **** * * ** * *** ** ** *** ** ****
** *** * *** * * *** * **** ** *** ** *** * * ** * *
** * * ** ** *** ** * *** **** * *** ** *** * ** * * *** *** ** *** ** ';
** ** * * * * * * * ***** ****** ** * ** *** * * ** * ** **** ***
* * **** * **** *** * * * * *** * *
*** * * ***** * * **** ** * * * ** * ***
    }
** *** *** ** * ** * *** * *** ** * *
    {
* * ** * ** * * ** **** * * * **** ** ** * ** * ** * *
** *** * * * * ***** ** * * ** ****
    }
    reverse[index]='\0';
* ** * * *** ******* ** * ****** ** ****
*** ******** ***** ** ** ** **** * ** ** * * **** *
***** * * * * ** *** * *** ** **** * ** * *
    else
* * * * * ****** * *** **** **** ** * ** ** * ** * *** * * * * ** *

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

**** ** * ** * ** **** *** ** ** ** ** *** * * **** ** ** **** ** * * *** ';
* ** * ** ** *** ** * *** ***** ****** *** * * * * *** * * ** * **

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

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

}
answered
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>
#include <ctype.h>
int main()
{
** * ** ******** ** *** ** a[50],b[50];
* ** ** * *** **** ***** i,A[50],B[50],C[51],length_A=0, ** ****** * * ** *** ***
** * * * * ** ** **** * %s",a,b);
** * * ** * * * ** ********* *** * * * *
    {
** ***** **** *** ******* ** * * * * * * ** **
*** * * **** * ** * ** * *** ** * ** *** * *
    }
* *** * ** * ** * * * ** ** *** * *
    {
* *** ** **** * *** ** ** * * ***** *** * * ** * *** *
****** * * * ** **** ** ** * * * * ** *** * *
    }

// * * ** * **** ** ***** ** * * * *****
 // ** * ***** *** * * ** printf("%d",A[i]); printf("\n");
 // * ** * *** * * * *** *** * ***** ** ***** ** * *** * printf("%d",B[i]);

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

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

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

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

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

** * ** ** ** ** *** * * * 123
    // 45678
** * * * ****** * * * **** 0;
}
answered by (-196 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>
#include <ctype.h>

int main(){
* ** * *** ***** * * * c,d[51]={0},strlena,strlenb,len,end,e=0;
* ** ** * * ***** a[50],b[50];
**** ** *** * *** * *** %s",a,b);
** * * ** ** *** * ** * ** ** ** *
** * ** * *** * * * **** **
** ** * ** * * ** **** ** * * ** **** **
*** * * **** ** *** * * ** * * ****** * *** ********* **
    }
** ** **** *** ** * * *** ** ** ** * **
******* ** *** * * ** * ****** ** * * ** * ***** * ** * * ****
    }*/
** * * ** * * **** * ***** ** * ***** ** * *
** * * * * * * ** **** ** * ** * * ** * * ** * ** ****** ****
    }
* *** * ** * * * *** * *** **
* * * ** ** * ** * ** * ** ****** * * * ** *** ** *
*** * ***** * *** ** * ** **** * * ** * ** * * ** * * * *
** ** **** ** * * * * * ** * ********* *** **** ** ******* * * ***
** *** * * **** ** * ** *** ** * ***
    }
*** * ** * ******* * *** * **
***** * * * ** *** ** * * ** * * * ******* **** **
* * * ** ***** **** * * * *** * * ** *** **** ** ** * * **
* * **** * ** * * *** ** *** **** * **** ** ** **** * **** ** *
*** ** * ** * * * * **** * ** *** ** * *
    }
****** * * ** ** * * **** * *******
*** ***** ** * * * ** * * * * **** * **** *** **
    }
*** ** * * * ** ** ** 0;
}
answered by (-498 points)
edited by
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: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>

char a[50],b[50],sum[50],bb[50];
int i,al,bl,sl,big;
int main()
{
*** * ** **** *** ******** i<50; i++)
    {
* * ** * ** ** *** * * *** * ****
* * ** ******* ** **** * ** ** ** ***** ** ** *
* * * * ** ** *** * ** ***** ** * * * *** **
    }
** * * ** ** * * * ** * * ** ** ** ** ** ** * *
**** * * * **** * * * * ****** * *** *
* **** * **** **** * *** * **
*** ** * * * * * ***
**** ** * *** *** *** * (al>bl)
    {
* * ** * * * * * * **** **** * * **
    }
** **** ****** *** * *
    {
** ** ** * * * ********** * * * * ** * *** **
    }
* **** * *** ** * * ** * i<al; i++)
    {
* * ** * ** ***** *** ** * * * ** **** * * *
//printf("%c",sum[i]);
* * * * * * *

* * * ** ***** * * * * *** i<bl; i++)
** **** *** *** * * * *
*** ***** ** ** * * * * *** * ****** * ***
//printf("%c",sum[i]);
* ***** ****** * *****

**** * * ** * *** * * * * i<big; i++)
* * * ** * *
******** *** **** ** **** * * * ** ** * ***** * **** *
* * * *** ***** * * ** * ** * ** * * **** * ** (sum[i]>'9')
** * * * * * *** * * *** * * * *** **
* * ** **** * * ** *** * **** * ** ***** *** *** ** * ** ** ***** ** *
* ** **** ******* ** * * *** **** ** * * ** * ** ** ** *** **** * * *
** * * * ***** * * * * *** * ** * * * * * *** ** * * ****** ***
*** ** * ** **** *** *** * * **** * ***** * * * ** ****** **** ** * * ** ** * **
* **** * * * * * ******* ** *** * ** * *** * * * ** * * ****** *
* * * ** * ** * * * **** ** * * * * ** ***** * ******* * ***** * * **** *** **
***** *** *** ** * * * ** * ***** * ***** * *** * * * ** * * * *** ** * ** ** ** **** **

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

* ** ** ** **** ** * i>=0; i--)
*** * ** ***** * * **
* * ****** * * ****** ***** ** ** * ** * ** **** *** * * * * *
**** ****** * ** ** ****
* ** * * *****
}
answered by (-336 points)
edited by
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: Correct output
Case 1: Correct output
Case 2: Wrong output
0 0
Case 0: Correct output
Case 1: Correct output
Case 2: Correct output
0 like 0 dislike
Hidden content!
*** *** *

int **
{

int ** * * * ** **** *
* * ***
int **

*** * * * s1);
* * **** * ***** s2);
for **** ! = ***
* * * * ** ** *** * * * * = * ** = '0';
** *** * * * * * ** *
* * * * ***** ** **** ! = ** * *
*** * *** *** ** * * ** = * * = *
* ******* * *** *
}






0;


}
answered by (323 points)
edited by
0 0
prog.c: In function 'main':
prog.c:14:1: error: expected declaration or statement at end of input
 {
 ^
prog.c:14:1: error: expected declaration or statement at end of input
0 0
prog.c: In function 'main':
prog.c:14:1: error: expected declaration or statement at end of input
 {
 ^
prog.c:14:1: error: expected declaration or statement at end of input
0 0
prog.c:8:1: error: expected '=', ',', ';', 'asm' or '__attribute__' before 'int'
 int main()
 ^~~
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
prog.c: In function 'main':
prog.c:7:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '.' token
 char s1[50]. s2[50];
            ^
prog.c:7:12: error: expected expression before '.' token
prog.c:10:13: error: 's1' undeclared (first use in this function)
 scanf("%s", s1);
             ^~
prog.c:10:13: note: each undeclared identifier is reported only once for each function it appears in
prog.c:11:13: error: 's2' undeclared (first use in this function)
 scanf("%s", s2);
             ^~
prog.c:12:18: error: expected ';' before '!' token
 for (l1=0;s1[l1] ! = '\0';l1++){
                  ^
prog.c:15:22: error: expected ';' before '!' token
     for (l2=0;s2[l2] ! = '\0';l2++){
                      ^
prog.c:28:1: error: expected declaration or statement at end of input
 }
 ^
0 like 0 dislike
Hidden content!
#include<stdio.h>
#include<string.h>
int main(void)
{
    int i,j,aa,bb,cnt=0,sum[51]={0};
    char a[51],b[51];
    scanf("%s %s",a,b);
    aa=strlen(a)-1;
    bb=strlen(b)-1;
*** ** * *** *** * ** *** ***** * * * *** * **
** *** **** * * ** *********** * ** * *** **** **
* * ***** ***** * ** * * * ** ** ** * *** * *** ** * *** ** *** ** ** ** * * **
** * ** * *** * * ** ** * ***** ***
*** ** *** *** * ****** * * ** * * * *** * * ** **
* * * ***** * *** * * * ****** *** * *****
**** * * * ** * * ** ** * * ** ** * *** * * ****** * * ***** * * *
*** * * ** ** ** ** * *** *** ****** *
* ** ** ** * ** ** * *** *** **** ** ** * * ***** ** *
* ** ** **** *** * *** * **
** ****** ** * ** * * ** * * ** * **** * ** ** *** * * * ****

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

** * ** ** * **** * * * * *** ** * ** *
** * **** * * * ** ******** ***** * * ***** * * * ** *
* * * * ******* ** * * ** * ** * ***
** * * * * * ******* ** * **** * ** *** * *** ***** ** ******** ** || cnt!=0)
*** *** **** * ***** ** ******* * * * * * ** * * * **** * * * * *** ***** * **
** ** *** *** **** ***** ** **** * **** ** *********** * * ** ** * * * *** * *** *** * * * * * *
**** *** ** * * ** *** ** * * * ** * ** *** ** ** * * * * **** * * * ***

    }

    return 0;
}
answered by (-304 points)
edited by
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: 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
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
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: 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
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(){
    char a[50],b[50],sum[51];
***** **** * ********* i=0;i<51;i++) sum[i]=-1;
* ** * * ** ******* **** * %s",a,b);


    int n=strlen(a),m=strlen(b);
    int stop=n>m?n:m;

    int carry=0;
******* * * * * ** ** * i=1;i<=stop;i++){
*** * ** ** ** ** ****** * ** ** * * * ** * ** ** ** * * * ** ** * q,w;
* * * ** *** ** * * **** ** ** * * **** * * *** * ** *** *********
**** **** * ** ** ** ** **** **** ******* ** ****** * * ** * * * ** * ** * * * ** ** **** *** * * *** *
* ***** * * * * ** ****** * * ** *** ********* ** *** ** * * ** if(m<i)
**** ** * ** ** * **** * * ** * ** ** *** ********* ******* ** * ** * ** *** * * ** * *
* * * * * * * * ** * ** **** * ** * ** *** ** * * * * ** *
*** * *** *** * ** ** **** ** * *** ***** *** *** * *** ** *** ** ***** ** * **** *** **** **** * * * *

******* * ** * * * * * * * **** ** ** ** * * ** * * ** * * * * * *** *** * *
* ***** * ** * * * * *** **** * * * ** * ** * *** * ** **** *** * ** * ** ** * * * * **** * * * *
* * * * * * * *** ** * * * ** ** * ** *** ** **** * **** * *** * * ** *** ** ** *
****** ** ** * ** * * *** ** *** * * ******* * **** * *** ***** *** * ** * * ** * ** * *** * sum[stop-i]=1;
* ** * ** ** **** ** *** ** * ** * ** ** * ** ** *** * * * * * *** * *** * * ** * sum[stop-i]=0;
* ** * *** ** ** * *** * *** *** ** ** * * **** * *** ***
* ** *** **** *** * **** * ** ** *** * ** *** **** ** ******* * * *
* * *** * * ** * * ** * ** *** ** * * ** ** * *** ** ** * **** * * ****** *** * * ** * * *
* ** ** * ** *** * * * * ** ** * * * * ** ** * *** * ** ******
    }

* ** ** * ** *** *** i=0;i<51;i++){
**** *** * * * *** * * * * ** *** * ** **** ** printf("%c",sum[i]+'0');
    }


******* *** * * * ***** * *** * 0;
}
answered by (-116 points)
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.71.254.168
©2016-2025

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
| 12.7k 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
| 11.7k 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
| 13.3k 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
| 10.5k 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
| 2.7k views
12,783 questions
183,442 answers
172,219 comments
4,824 users