how can write a pascal program that do minus,sum and muliply tow number with 50 digit???
please answer or mail to me.

Recommended Answers

All 6 Replies

50 digit? Are these significant digits?
Please add more information about the problem. :'(

50 digit? Are these significant digits?
Please add more information about the problem. :'(

my intention is a program that calculate sum,minus and muliply of
two number with 50 integer number.
for example:12345678912345678912345678912345678912345678912345*or-or+1234567891234567891234567891234567891234567891234

the above numbers too much.... :S
free pascal reference

{
Real types
-Free Pascal uses the math coprocessor or emulation for all its floating-point calculations.
The REAL native type is processor dependent,but it is either SINGLE or DOUBLE.Only the IEEE floating point types are supported,and these
depend on the target processor and emulation options.
The real TURBO PASCAL compatible types are listed :

TYPE	  RANGE			SIGNIFICANT DIGITS	SIZE(BYTE)
REAL	  PLATFORM DEPENDENT      	???             4 OR 8
SINGLE    1.5*10^-45..3.4*10^38 	7-8		4
DOUBLE    5.0*10^-324..1.7*10^308	15-16		8
EXTENDED  1.9*10^-4932..1.1*10^4932	19-20		10
COMP      -2*10^64+1..2*10^63-1		19-20		8
CURRENCY  -922337203685477.5808..922337203685477.5807	8

- The COMP type is,in effect,a 64-bit integer and is not available on
all target platforms.The CURRENCY type is a fixed-point real data type
which is internally used as an 64-bit integer type,automatically scalled with a factor 10000,this minimalizes rounding errors.
}

Where do you want to store those 50 digits????? :?:
If you can store them,then( alert me too :D ) you can use pointers to manipulate the memory addresses of those numbers :idea:

try this

var a:string;
b:string;
c:string;
len:integer;
var i:byte;
sum:byte;
puluh:byte;
satuan:byte;
begin
a:='66476578';
b:='57813241';
len:=length(a);
if length(b)>len then begin
len:=length(b);
while length(a)<len do a:='0'+a;
end
else while length(b)<len do b:='0'+b;
c:='';
puluh:=0;
writeln(a,#13#10,b);
for i:=len downto 1 do begin
sum:=(ord(a)+ord(b))-48*2+puluh;
puluh:=sum div 10;
satuan:=sum mod 10;
c:=chr(satuan or $30)+c;
{
jika perlu melihat proses dr awal sampai akhir
writeln(i,' ',a,'+',b,'=',sum:3,' ',puluh);
}
end;
if puluh>0 then c:=chr(puluh or $30)+c;
writeln(c);
end.

the above numbers too much.... :S
free pascal reference

{
Real types
-Free Pascal uses the math coprocessor or emulation for all its floating-point calculations.
The REAL native type is processor dependent,but it is either SINGLE or DOUBLE.Only the IEEE floating point types are supported,and these
depend on the target processor and emulation options.
The real TURBO PASCAL compatible types are listed :

TYPE	  RANGE			SIGNIFICANT DIGITS	SIZE(BYTE)
REAL	  PLATFORM DEPENDENT      	???             4 OR 8
SINGLE    1.5*10^-45..3.4*10^38 	7-8		4
DOUBLE    5.0*10^-324..1.7*10^308	15-16		8
EXTENDED  1.9*10^-4932..1.1*10^4932	19-20		10
COMP      -2*10^64+1..2*10^63-1		19-20		8
CURRENCY  -922337203685477.5808..922337203685477.5807	8

- The COMP type is,in effect,a 64-bit integer and is not available on
all target platforms.The CURRENCY type is a fixed-point real data type
which is internally used as an 64-bit integer type,automatically scalled with a factor 10000,this minimalizes rounding errors.
}

Where do you want to store those 50 digits????? :?:
If you can store them,then( alert me too :D ) you can use pointers to manipulate the memory addresses of those numbers :idea:

i want to store this in two array and then calculate.

let's see those arrays a bit closer,ok.
first will be example a and the second'll be b.
1.Are the above arrays has fifty elements?

{just example}
type digits = array[1..50]of integer;
var a,b:digits;

or
2.has got these arrays only one element that stores the 50 digits? As string?

var a,b:string;{'cause string is a char array too}

3.And how do you want to calculate with them?
by elements?

{just example}
var a,b:digits;
         x:integer;{if you want to divide then use real type here}
      i:=integer;{loop}
begin
   x[1]:=a[1] + b[1];
   ...
   ...

4.And how many the max number in one element?
0..9 ?
or if we add two numbers together then the result can
be more then 10?Or stay remainder to add...?

...
...
a[1]:=7;    b[1]:=5;
a[2]:=8;    b[2]:=6;
a[3]:=9;    b[3]:=3;

x[2]:=a[2]+b[2]; {x[2] = 14}
...
...

5. And what about the remainders?

...
...
a[1]:=7;    b[1]:=5;
a[2]:=8;    b[2]:=6;
a[3]:=9;    b[3]:=3;
{if we add a[1]+b[1] then }
x[1]:=a[1]+b[1]; {it is 12}

{or you try to the last numbers to add}
for i:=3 downto 1 do begin
   x[i]:=a[i]+b[i];
{if there were remainders then}
   x[i-1]:=x[i-1]+remainder
end;

too many question,to answer

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.