Solved

Sum Of  two positive integers!

Posted on 2000-02-22
2
233 Views
Last Modified: 2010-04-16
Write a program to compute the sum of two positive integer numbers.  Each number is up to 20 digits.  Do not use any REAL or LONGINT types in the program.

Must use stacks, digits must be read in one-by-one.  For example 2345678 + 9999999999, must be read in 2, then 3, then 4, and so on.  if sum of two digits is greater than 9, u must carry it over, so the next part can use it.
0
Comment
Question by:hipopynonamous
2 Comments
 
LVL 2

Expert Comment

by:kellyjj
ID: 2547666
We can't do your homework for you.  Try it yourself, and then post the code you are having probs w/.
0
 
LVL 3

Accepted Solution

by:
Alisher_N earned 100 total points
ID: 2547677
var
   s1,s2,s3 : String;
   j,j1,j2,j3,max,carry1 : Byte;
begin
  Write( 'enter first number: ' );
  Readln( s1 );
  Write( 'enter second number: ' );
  Readln( s2 );

  max := Length( s1 );
  if max < Length( s2 ) then max := Length( s2 );
  while Length( s1 ) < max do s1 := '0' + s1;
  while Length( s2 ) < max do s2 := '0' + s2;
  carry1 := 0; s3 := 0;
  for j := max downto 1 do begin
    j1 := Ord( s1[j] ) - $30; {ASCII -> value }
    j2 := Ord( s2[j] ) - $30;
    j3 := j1 + j2 + carry1;
    carry1 := j3 div 10;
    j3 := j3 mod 10 + $30;
    s3 := Chr( j3) + s3;
  end; {for}
  if carry1 = 1 then s3 := '1' + s3;
  writeln( 'result: ', s3 );
end.

0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
In this article, I will show you HOW TO: Create your first Windows Virtual Machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, the Windows OS we will install is Windows Server 2016.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now