0 like 0 dislike
10k 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

 

[Exercise] Coding (C) - asked in Chapter 13: Strings by (5.2k points)
ID: 40714 - Available when: 2018-01-04 18:00 - Due to: Unlimited

edited by | 10k views

44 Answers

0 like 0 dislike
Hidden content!
#include **** * ** *

#define LEN 51

int ** * * ** n[])
{
* ****** * tmp[LEN]; * **** i,m;
* ** *** * * * **** ***** *** *  { * * * *  }
* * * *** ** ** * * ** ** ****  { * **** * * -1;  }
** * * ** ** **
*** *** * ** ******  { ** * ** ** ** **  }
}

void * **** n[])
{
* ** * * i,p,f=0;
** *** ** * ** ** *** *
* * * * ** ** *** * *** *  { * ** *  }  }
* **** ***** **
** * * * ** * * **** * * * **** * ** * * * ***
* **********  { * * * ****** * *** **
}

void * ** *** a[], char b[], char c[] )
{
* * ***** * * i,tmp=0;
* * * * * ** ** **
* * * * ***
**** * * * * ** ** * * ****** * *
* * * *** ** * * * ** * *** ** * * * ** * * **** *  }
* ** * *** ** **** * ** ** tmp=0; *
** * * **
}

int main(){
* ***** * * * ** * * *** ** * *
** * * * ** **** * **** *** ***
*** * * *** ** * ***** * * **
* * **** *** * ** ** * ***
* ** *** * * * * * ** * * *
** * * ** ** * ******* 0;
}
answered by (-116 points)
0 0
prog.c: In function 'InputBigNum':
prog.c:10:5: warning: implicit declaration of function 'strlen' [-Wimplicit-function-declaration]
   m=strlen(tmp);
     ^~~~~~
prog.c:10:5: warning: incompatible implicit declaration of built-in function 'strlen'
prog.c:10:5: note: include '<string.h>' or provide a declaration of 'strlen'
0 like 0 dislike
Hidden content!
#include <stdio.h>
#include <string.h>
#define LEN 300

int  Input(char n[]){
****** ** **** *** * * * * * * *** * * * * *** *** * * ** * *** * s[LEN];

* * *** ** * *** * * * * * ** * * ***** * ** * * ** *** ** i, l;

* ** * * * ** * * ******** *** * ** ***** * ****** * ** * ******** * i<LEN; i++){
* ** * * * ** * ** * * * * ** ** * * * ** * * * ******* * * **** * * **
*** ** * ** * ** **** *** * **** * ** ****** *****
** * ** *** * * **** * ** ***** * * * ** ** *** ** * ** * * * * ** * * s)<1){
** * ** ** * * * * *** ** ******* * ** ** *** * *** * * *** *** * * * * -1;
** * ** * **** * **** ** *** * * * * * * ** ***
*** ** *** * * * * * * ** * ***** ******* *** * * **** *
* * * ** * * * ** * * *** * * * * i<l; i++){
** ** *** * ** ** * **** * ** * *** * * * * ** * *** * * * **** * * ** ** ** ** *** ** * *
* ** * * ** * * * * *** * * * ** ****** * *** * ****** *
*** * * ** **** ** ** ***** *** ** ** * ** * * * ** * * ** 0;

}

void Print(char n[]){
* * ** ** ** * * * * * ** *** * * *** * * ******* **** i;
** ***** * ***** * * * * *** * **** ** * ********* **** * * ** ** * i>0; i--){
* * *** * **** ** * ******* ** * * * * * ** ** * ** ** * * * ** ** * ** * ** *** *** break;
* ** ** * *** ** *** *** * ** * * * * **** * ***** * **
****** ** * ** * * * ** * *** ** ** * ** * * ** * * * * ****** ** * ** i>=0; i--){
** *** * *** * * ******* ** *** ** *** ** ****** * * *** **** ** * **** **** * * ** **** * ** *** n[i]);
* ******* ** * * * * ** * * ***** ** *** * * * ** * * ***** * ***
* ** * * * * **** * * * *** ** ** ***** * * * * ** * * ****** * **
}

void Add(char a[], char b[], char c[]){
***** * * ** ** * *** ** ****** * * ** * ** *** * ***** i;
****** * ** * * **** * **** **** **** * i<LEN; i++){
* ** ** ** ******* * ******* * ** ** ***** * ** * ****** * * *** *
         }
* ***** * * ** *** * * * ** ** * * * * *** * * * * i<LEN-1; i++) {
*** * * ** ** ** * ** ** ** * * * * ** ** * ** ** * ** ** ***** ** **** {
** * * * * * *** * * ** * * ** ** ** * ** *** ** **** **** ********* *** ** * * * ** ****
**** **** * * **** * **** * *** **** * * * ** *** * ** ** * *** **** * * * * ** ** *** * **** * ******
* * * *** * **** * * * ** *** ** ***** *** ****** *** * * ** * *** **** **** ** * **** *
        }
}

void main(){
     char a[LEN], b[LEN], c[LEN];
     Input(a);
     Input(b);
     Add(a, b, c);
     Print(c);
}
answered by (-32 points)
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!
* ** *** ****
int main()
{
* * **** * * * *** * * a,b;
** * * * **** * ** *** * * * ***** * *****
* **** * **** ** ** * * * ***** ** ** * * * **** *





}
answered by (-329 points)
0 0
Case 0: Correct output
Case 1: Wrong output
Case 2: Wrong output
0 0
nice try hahaha
0 0
This is the best one!!!! hahahahaha
0 like 0 dislike
Hidden content!
* *** *
** ***** ** ** * **

int main()
{
char A[50],B[50];
int C[51]={0};
int i,j;
scanf("%s %s",A,B);
* ** * * * ** ** **** ** * j++)
{
**** ** ** * ** * * * **
}
* **** * * ** * j++)
{
** ** **** ** ** ** * * ***
}
for(i=0;i<51;i++)
{
** * * *** **** *** * ** ** * ** ***
** * ** * * *** ****
* * * *** * * * *** * **** * *** *** ** ***
* ** *** ** * * * *** ** * ** * ******** *
* * ** * *** ** **
}
for(i=50;i>=0;i--)
{
**** * * * **** * *
* ** ** * *********** *
** * * ** * * ** *** **** * *** *** *** ** ** **
* * ** *** * ***
** ** * * * * * **** * ***** ** ** *** ** * *
** * * * ** * * * ***
* ** *** * * ** *****
}
}
}
answered by (5.2k 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.70.50.27
©2016-2025

Related questions

1 like 1 dislike
85 answers
[Exercise] Coding (C) - asked Oct 26, 2017 in Chapter 6: Loops by semicolon (5.2k points)
ID: 28914 - Available when: 2017-10-26 18:00 - Due to: Unlimited
| 17.3k views
12,783 questions
183,442 answers
172,219 comments
4,824 users